c++ - 在没有 Xcode IDE 的情况下开发 C++

标签 c++ xcode opengl operating-system max

我想在 mac os 上开发 C++ 程序,我已经安装了带有一堆框架的 Xcode。

但是我想在没有 Xcode IDE 的情况下编写代码,而是编写我自己的 makefile 并直接使用 gcc(Xcode 附带)进行编译/链接。

以一个opengl程序为例。我试着用命令编译它:

gcc -I/usr/include/ -I/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/GLUT.framework/Headers/ -I/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/OpenGL.framework/Headers -L/usr/lib -L/usr/X11/lib/ -L/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/OpenGL.framework/Libraries/ -lGL -lGLU -lGLUTt main.cpp

gcc -I/usr/include/ -L/usr/lib -framework OpenGL -framework GLUT -lm main.cpp

但是他们以链接错误告终

Undefined symbols:
"std::basic_ostream

::operator<<(long)", referenced from: reshape(int, int)in ccKBRSF9.o display() in ccKBRSF9.o "___gxx_personality_v0", referenced from: ___gxx_personality_v0$non_lazy_ptr in ccKBRSF9.o (maybe you meant: ___gxx_personality_v0$non_lazy_ptr) "std::ios_base::Init::~Init()", referenced from: ___tcf_0 in ccKBRSF9.o "std::basic_string, std::allocator ::operator[](unsigned long) const", referenced from: std::__verify_grouping(char const*, unsigned long, std::basic_string, std::allocator > const&)in ccKBRSF9.o std::__verify_grouping(char const*, unsigned long, std::basic_string, std::allocator > const&)in ccKBRSF9.o std::__verify_grouping(char const*, unsigned long, std::basic_string, std::allocator > const&)in ccKBRSF9.o "std::basic_ostream >& std::operator<< (std::basic_ostream >&, char const*)", referenced from: keyboard(unsigned char, int, int)in ccKBRSF9.o keyboard(unsigned char, int, int)in ccKBRSF9.o keyboard(unsigned char, int, int)in ccKBRSF9.o reshape(int, int)in ccKBRSF9.o display() in ccKBRSF9.o "std::ios_base::Init::Init()", referenced from: __static_initialization_and_destruction_0(int, int)in ccKBRSF9.o
"std::basic_string, std::allocator >::size() const", referenced from: std::__verify_grouping(char const*, unsigned long, std::basic_string, std::allocator > const&)in ccKBRSF9.o "std::cout", referenced from: __ZSt4cout$non_lazy_ptr in ccKBRSF9.o (maybe you meant: __ZSt4cout$non_lazy_ptr) ld: symbol(s) not found collect2: ld returned 1 exit status

我错过了什么吗?

最佳答案

使用g++ 编译C++。它是 GCC 的 C++ 前端。例如:

g++ -I/usr/include/ -L/usr/lib -framework OpenGL -framework GLUT -lm main.cpp

关于c++ - 在没有 Xcode IDE 的情况下开发 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3850817/

相关文章:

c++ - Coverity 发现 : Not restoring ostream format (STREAM_FORMAT_STATE)

c++ - std::cout << 预测为任意 double 显示的自动字段宽度

c++ - 我该如何修复 MSVC 2005 错误 : unresolved external symbol __environ

c++ - 对整个 vector 应用条件

c++ - 预期的 ;在顶级声明符之后,xcode中的错误

OpenGL render-to-texture-via-FBO——不正确的显示与正常的纹理

OpenGL、VAO 和多个缓冲区

ios - "Expression was too complex to be solved in reasonable time..."是什么意思,我该如何解决?

iphone - 多个 Xcode,如何选择打开哪个 xcodeproj 文件

java - 我如何确保这个正方形移动并且不会使用 openGL 扩展?