My Xcode target links against hdf5 library (using the Link Binary with Libraries build phase). libhdf5 is installed using MacPorts, thus /opt/local/lib contains both the dyn
My case with Xcode 4.5:
When I drag and drop a static C library (a 3rd party library compiled with GNU Autotools) to project's frameworks (Project Navigator > Frameworks
) the linker seems to thinks that's a dynamic library and adds -L -l
flags:
-L/path/to/libfoodir -lfoo
The linking fails because there is no /path/to/libfoodir/libfoo.dylib
.
The linker command can be seen from:
Log Navigator > select a Build log > select a Link line and expand it
The linking succeeds when I add a full path (/path/to/libfoodir/libfoo.a
) to the linker settings:
Targets > Build Settings (all) > Other linker flags
Under XCode 11.3.1, targeting MacOS
Tried to add absolute lib path to Other linker flags
. But that doesn't work. So I copied required *.a files (ln -s may also work) to project dir and it worked like a charm.
Use the "-static" switch for linking: GCC link options
In reaction to your comment on Eduard Wirch' answer: you can also control static linking for this one library only, if you replace -lhdf5 by -l/full/path/to/libhdf5.a
Had this exact same problem and despite this being an old post, I thought I'd share what I had to do to make this work.
Usually you do just provide the switch '-static' to the linker however, with Xcode this causes all libs including the crt to be linked statically. I got the error:
can't locate file for: -lcrt0.o
When I tried this.
The thing which worked for me was to replace:
-lmylib
with
/path/to/libmylib.a
Note: the -l is dropped.