[CMake] Specifying (partially) load order of DLLs

Wheeler, Frederick W (GE, Research) wheeler at crd.ge.com
Wed Sep 24 20:13:40 EDT 2008


CMake List:

On one of our projects we have a very strange problem with 2
third-party DLLs (no source) and the order in which they are loaded at
runtime.  The executable needs A.dll and B.dll, which do not depend on
each other - they are completely independent.  If A.dll is loaded
first, all is fine.  If B.dll is loaded first, the program crashes at
load time - before even the first line of code in the program is
reached - we have no idea why and little hope of figuring out why.

So, this is odd, and was very hard to figure out, but we can work
around the problem easily enough.  To make sure A.dll is loaded before
B.dll we use the following line in CMake ...

TARGET_LINK_LIBRARIES( A B )

This worked fine in CMake 2.5.x, but in 2.6.1, even with the above
line, B.dll might be loaded before A.dll (seen with the tool
depends.exe).

Here is my suspicion: Cmake 2.6.1 is a bit smarter, so we don't get
the side-effect we need.  When A depends on B, A must come before B on
the link line for a static link, of course.  But for shared objects I
think the order does not really matter, since the whole shared library
is loaded.  Maybe CMake knows that, so it does not worry about the
link-line order of DLLs?

So I have two questions:

1. Could my suspicion above about CMake 2.6.1 and run-time link order
of shared objects be correct?

2. Is there a better or more reliable way than TARGET_LINK_LIBRARIES(
A B ) to get A.dll loaded before B.dll at the run-time linking stage?

Thanks,
Fred Wheeler


More information about the CMake mailing list