加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在没有Xcode IDE的情况下开发C.

发布时间:2020-12-14 17:10:56 所属栏目:百科 来源:网络整理
导读:我想在mac os上开发C程序,我已经安装了 Xcode和一堆框架. 但是我想编写没有Xcode IDE的代码,只需编写我自己的makefile并直接编译/链接gcc(随Xcode一起提供). 以opengl程序为例.我试着用命令编译它: gcc -I/usr/include/ -I/Developer/SDKs/MacOSX10.6.sdk/S
我想在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*,
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)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*,
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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读