Xcode chooses dynamic library to link although static version was explicitly specified

FB9843414

Just encountered a very annoying bug in Xcode. Let's say you want to link a static library like C++ fmt. If the directory you specify as library search path contains both a dynamic libfmt.dylib as well as the static libfmt.a version of that library, Xcode will choose the .dylib version - regardless whether you explicitly specified the .a binary under the target's build phases.

Hopefully this nasty bug can finally be fixed. This stackoverflow post is over 4 years old, but saved my sanity.

Answered by wriker in 701491022

In case someone else has the problem: a temporary manual workaround for this is to move the static binary (e.g.libfmt.a) to a subdirectory, maybe static/ and use this as the library search path. This can of course lead to problems if you installed the library with a package manager like brew and want to update. I hope this can help someone until Apple fixes this.

Accepted Answer

In case someone else has the problem: a temporary manual workaround for this is to move the static binary (e.g.libfmt.a) to a subdirectory, maybe static/ and use this as the library search path. This can of course lead to problems if you installed the library with a package manager like brew and want to update. I hope this can help someone until Apple fixes this.

Thanks for the bug report + workaround! Your bug has been sent to the Xcode team for review.

Xcode chooses dynamic library to link although static version was explicitly specified
 
 
Q