到 -lobjc 还是不到 -lobjc?
海湾合作委员会手册说:
file.m
Objective-C 源代码。请注意,您必须链接到
libobjc
让 Objective-C 程序运行的库。
并且:
-lobjc
您需要这种特殊情况的
-l
选项才能链接
Objective-C 或 Objective-C++ 程序。
但是,我可以简单地成功编译程序:
$ cc prg.m -framework Foundation
当您包含框架时,它是链接器默认值吗?如果是的话,它在哪里 有记录吗?无论如何,程序都会被链接:
$ otool -L a.out
a.out:
/System/Library/Frameworks/Foundation.framework/.../Foundation (...)
/usr/lib/libSystem.B.dylib (...)
--> /usr/lib/libobjc.A.dylib (...)
/System/Library/Frameworks/CoreFoundation.f...k/.../CoreFoundation (...)
GCC manual says:
file.m
Objective-C source code. Note that you must link with the
libobjc
library yo make an Objective-C program work.
And:
-lobjc
You need this special case of the
-l
option in order to link an
Objective-C or Objective-C++ program.
However, I can succesfully compile a program with simply:
$ cc prg.m -framework Foundation
Is it a linker default, when you include a framework? If so, where is it
documented? The program gets linked anyway:
$ otool -L a.out
a.out:
/System/Library/Frameworks/Foundation.framework/.../Foundation (...)
/usr/lib/libSystem.B.dylib (...)
--> /usr/lib/libobjc.A.dylib (...)
/System/Library/Frameworks/CoreFoundation.f...k/.../CoreFoundation (...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为
Foundation
框架已经与libobjc
链接。因此,在 OSX 上,仅当您不链接到
Foundation
框架时(这种情况非常罕见),您才需要-lobjc
选项。This is because the
Foundation
framework is already linked withlibobjc
.So on OSX, you'll need
-lobjc
option only if you doesn't link with theFoundation
framework (which is very rare).