开发者

develop C++ without Xcode IDE

开发者 https://www.devze.com 2023-01-18 18:50 出处:网络
I want to develop C++ programs on mac os and I have installed Xcode with a bunch of frameworks. However I would like to write code without Xcode IDE but just write my own makefile and directly compil

I want to develop C++ programs on mac os and I have installed Xcode with a bunch of frameworks.

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).

Take a opengl program as example. 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

or

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

::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:开发者_如何学Go ___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

Did I miss something?


Use g++ to compile C++. It's the C++ front-end for GCC. E.g.:

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


You could also use clang++, but in both cases you will have to use the C++ compiler, or the -lstdc++ option.

0

精彩评论

暂无评论...
验证码 换一张
取 消