To -lobjc or not to -lobjc?
GCC manual says:
file.m
Objec开发者_如何学JAVAtive-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 (...)
This is because the Foundation
framework is already linked with libobjc
.
So on OSX, you'll need -lobjc
option only if you doesn't link with the Foundation
framework (which is very rare).
精彩评论