开发者

To -lobjc or not to -lobjc?

GCC manual says:

file.m

    Objec开发者_如何学JAVAtive-C source code. Note that you must link with thelibobjc

    library yo make an Objective-C program work.

And:

-lobjc

    You need this special case of the-loption 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).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜