我想在mac os上开发C ++程序,我已经在Xcode上安装了一堆框架。
但是我想编写没有Xcode IDE 的代码,但只需编写我自己的makefile并直接编译/链接gcc(随Xcode一起提供)。
以一个opengl程序为例。我试着用命令编译它:
gcc -I / usr / include / -I /开发商/软件开发工具包/ MacOSX10.6.sdk /系统/资源库/框架/ GLUT.framework /头/ -I /开发商/软件开发工具包/ MacOSX10.6.sdk /系统/资源库/框架/ OpenGL.framework /头 -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
但他们最终导致链接错误
未定义的符号:
“标准:: basic_ostream:: operator<<(long)“,引自: reskpe(int,int)在ccKBRSF9.o中 display()in ccKBRSF9.o“___gxx_personality_v0”,引用 从: 在ccKBRSF9.o中___ gxx_personality_v0 $ non_lazy_ptr (也许你的意思是:___ gxx_personality_v0 $ non_lazy_ptr)“std :: ios_base :: Init :: ~Init()”, 引自: ccKBRSF9.o中的___tcf_0“std :: basic_string, 的std ::分配器 :: operator [](unsigned long)const“,引自: std :: __ verify_grouping(char const *,unsigned long, 的std :: basic_string的, std :: allocator>常量&安培)在 ccKBRSF9.o std :: __ verify_grouping(char const *,unsigned long, 的std :: basic_string的, std :: allocator>常量&安培)在 ccKBRSF9.o std :: __ verify_grouping(char const *,unsigned long, 的std :: basic_string的, std :: allocator>常量&安培)在 ccKBRSF9.o“std :: basic_ostream>& 的std ::运营商LT;< (std :: basic_ostream>&,char const *)“,引自: ccKBRSF9.o中的keyboard(unsigned char,int,int) ccKBRSF9.o中的keyboard(unsigned char,int,int) ccKBRSF9.o中的keyboard(unsigned char,int,int) reskpe(int,int)在ccKBRSF9.o中 ccKBRSF9.o中的display()“std :: ios_base :: Init :: Init()”, 引自: ccKBRSF9.o中的__static_initialization_and_destruction_0(int,int)
“的std :: basic_string的, std :: allocator> :: size()const“, 引自: std :: __ verify_grouping(char const *,unsigned long, 的std :: basic_string的, std :: allocator>常量&安培)在 ccKBRSF9.o“std :: cout”,引用 从: 在ccKBRSF9.o中__ZSt4cout $ non_lazy_ptr (也许你的意思是:__ ZSt4cout $ non_lazy_ptr)ld:未找到符号collect2:ld返回1退出 状态
我错过了什么吗?
答案 0 :(得分:8)
使用g++
编译C ++。它是GCC的C ++前端。 E.g:
g++ -I/usr/include/ -L/usr/lib -framework OpenGL -framework GLUT -lm main.cpp
答案 1 :(得分:0)
您也可以使用clang++
,但在这两种情况下,您都必须使用C++
编译器或-lstdc++
选项。