[英]develop C++ without Xcode IDE
I want to develop C++ programs on mac os and I have installed Xcode with a bunch of frameworks. 我想在mac os上开发C ++程序,我已经安装了Xcode和一堆框架。
However I would like to write code without Xcode IDE but just write my own makefile and directly compile/link with gcc (shipped with Xcode). 但是我想编写没有Xcode IDE的代码,只需编写我自己的makefile并直接编译/链接gcc(随Xcode一起提供)。
Take a opengl program as example. 以opengl程序为例。 I tried to compile it with the command:
我试着用命令编译它:
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 / -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
or 要么
gcc -I/usr/include/ -L/usr/lib -framework OpenGL -framework GLUT -lm main.cpp
gcc -I / usr / include / -L / usr / lib -framework OpenGL -framework GLUT -lm main.cpp
But they ended up with linking error 但他们最终导致链接错误
Undefined symbols:
未定义的符号:
"std::basic_ostream“的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() i
:: operator <<(long)“,引用自:ccKBRSF9.o中的reshape(int,int)。在ccKBRSF9.o”___gxx_personality_v0“中的display(),引用自:___ gxx_personality_v0 $ cc_BRKFF中的non_lazy_ptr(也许你的意思是:___ gxx_personality_v0 $ non_lazy_ptr)“std :: ios_base :: Init :: ~Init()”,引自:ccKBRSF9.o中的___tcf_0“std :: basic_string,std :: allocator :: operator [](unsigned long)const”,引用from:std :: __ verify_grouping(char const *,unsigned long,std :: basic_string,std :: allocator> const&)在ccKBRSF9.o std :: __ verify_grouping(char const *,unsigned long,std :: basic_string,std ::在ccKBRSF9.o中的分配器> const&)std :: __ verify_grouping(char const *,unsigned long,std :: basic_string,std :: allocator> const&)ccKBRSF9.o“std :: basic_ostream>&std :: operator <<( std :: basic_ostream>&,char const *)“,引用自:ccKBRSF9.o键盘中的键盘(unsigned char,int,int)ccKBRSF9.o键盘中的unsigned char,int,int)(unsigned char,int,int )在ccKBRSF9.o reshape(int,int)ccKBRSF9.o display()i中 n ccKBRSF9.o "std::ios_base::Init::Init()", referenced from: __static_initialization_and_destruction_0(int, int)in ccKBRSF9.o
n ccKBRSF9.o“std :: ios_base :: Init :: Init()”,引自ccKBRSF9.o中的__static_initialization_and_destruction_0(int,int)
"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“std :: basic_string,std :: allocator> :: size()const”,在ccKBRSF9.o中引用:std :: __ verify_grouping(char const *,unsigned long,std :: basic_string,std :: allocator> const&) “std :: cout”,引用自:ccKBRSF9.o中的__ZSt4cout $ non_lazy_ptr(也许你的意思是:__ ZSt4cout $ non_lazy_ptr)ld:未找到符号collect2:ld返回1退出状态
Did I miss something? 我错过了什么?
Use g++
to compile C++. 使用
g++
编译C ++。 It's the C++ front-end for GCC. 它是GCC的C ++前端。 Eg:
例如:
g++ -I/usr/include/ -L/usr/lib -framework OpenGL -framework GLUT -lm main.cpp
您也可以使用clang++
,但在这两种情况下,您都必须使用C++
编译器或-lstdc++
选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.