[Cmake] How to build two libraries that mutually import functions
Brad King
brad.king at kitware.com
Thu, 25 Mar 2004 08:43:30 -0500
Karr, David wrote:
> Among the libraries that I build for a certain project,
> there are two mutually dependent libraries.
> Specifically, library A exports some functions that
> library B needs to import, and library B exports some
> functions that library A needs to import.
>
> I'm trying to build these libraries in Visual C++ 6.0.
> Apparently this means I have to run LIB first on one
> library to generate the .exp file, then I can build
> the other library, and finally I can finish building
> the first library.
>
> Frankly I don't even know how to get Visual C++ to do
> this automatically even if I create the workspace by hand.
> But I was hoping CMake would set up the workspace so
> that it builds correctly. So far, I have tried listing
> each library in a TARGET_LINK_LIBRARIES command in the
> CMakeLists.txt file of the other library, but the
> libraries still won't build.
>
> Does this problem have a known solution other than
> removing all mutual imports?
If the set of symbols to export from one of the libraries is reasonably
small, I think you can create a .exp file manually ahead of time and
include it in the source list for that library. I haven't actually
tried this, though, because none of our projects has this design.
> And by the way, what is the difference between
> TARGET_LINK_LIBRARIES and LINK_LIBRARIES?
TARGET_LINK_LIBRARIES adds linking rules to a specific target.
LINK_LIBRARIES causes the listed libraries to be linked into every
target seen after it in the directory containing the command and all
subdirectories. The LINK_LIBRARIES command is left over from an early
CMake methodology that was quite different. I've just updated the
documentation for this command in the CVS version to clarify this
difference for the next release.
-Brad