开发者

To -lobjc or not to -lobjc?

开发者 https://www.devze.com 2023-04-04 19:12 出处:网络
GCC manual says: file.m     Objec开发者_如何学JAVAtive-C source code. Note that you must link with thelibobjc

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

精彩评论

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

关注公众号