tags:

views:

1445

answers:

2

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 dynamic (.dylib) and static (.a) versions of the library.

The text output from the build shows that there is, as expected, a -lhdf5 in the linking step of the build. gcc seems to take the dynamic linked library over the static, however. Is there any way to force gcc (via a compiler switch or via Xcode) to statically link with libhdf5.a?

The only solution I've found is to copy libhdf5.a to the project (or other) directory and link against that copy, thus avoiding having dynamic and static versions in the same location.

+2  A: 

Use the "-static" switch for linking: GCC link options

Eduard Wirch
Will this force static linking of all libraries, or can it's application be controlled on a per-library basis?
Barry Wark
Actually it will link all libraries static.
Eduard Wirch
+2  A: 

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

yungchin