GCC manual says:
file.m
Objective-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
Foundationframework is already linked withlibobjc.So on OSX, you’ll need
-lobjcoption only if you doesn’t link with theFoundationframework (which is very rare).