开发 C++没有 Xcode IDE

发布于 2024-09-26 02:03:52 字数 2329 浏览 0 评论 0原文

我想在 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

但他们最终出现了链接错误

未定义的符号:
“std::basic_ostream

<块引用>

::operator<<(long)",引用自: ccKBSF9.o 中的重塑(int,int) ccKBSF9.o“___gxx_personality_v0”中的display(),引用 从: ccKBSF9.o 中的 ___gxx_personality_v0$non_lazy_ptr (也许你的意思是: ___gxx_personality_v0$non_lazy_ptr)“std::ios_base::Init::~Init()”, 参考自: ccKBSF9.o 中的 ___tcf_0 “std::basic_string, std::分配器 ::operator[](unsigned long) const",引用自: std::__verify_grouping(char const*, 无符号长整型, std::basic_string, std::分配器>常量&)in ccKBSF9.o std::__verify_grouping(char const*, 无符号长整型, std::basic_string, std::分配器>常量&)in ccKBSF9.o std::__verify_grouping(char const*, 无符号长整型, std::basic_string, std::分配器>常量&)in ccKBSF9.o“std::basic_ostream >& std::运算符<< (std::basic_ostream >&, char const*)”,引用自: ccKBSF9.o 中的键盘(无符号字符、int、int) ccKBSF9.o 中的键盘(无符号字符、int、int) ccKBSF9.o 中的键盘(无符号字符、int、int) ccKBSF9.o 中的重塑(int,int) ccKBSF9.o 中的 display() "std::ios_base::Init::Init()", 参考自: ccKBSF9.o 中的 __static_initialization_and_destruction_0(int, int)
“std::基本字符串, std::allocator >::size() const", 参考自: std::__verify_grouping(char const*, 无符号长整型, std::basic_string, std::分配器>常量&)in ccKBSF9.o“std::cout”,引用 从: ccKBSF9.o 中的 __ZSt4cout$non_lazy_ptr (也许你的意思是:__ZSt4cout$non_lazy_ptr)ld:找不到符号collect2:ld返回1退出 状态

我错过了什么吗?

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: ___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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幻梦 2024-10-03 02:03:52

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

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

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
瑶笙 2024-10-03 02:03:52

您还可以使用 clang++,但在这两种情况下,您都必须使用 C++ 编译器或 -lstdc++ 选项。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文