[CMake] Linking Behavior of Static Libraries on Windows

bpwlist at cox.net bpwlist at cox.net
Wed Mar 21 19:06:44 EST 2007


Part of my objection is that I want to limit how many in which libraries I have to distribute.

My project looks some thing like this:

main_src/
      main_exe (depends on main_shared_library)
      main_shared_library (depends on my_static_library_facade)
      my_static_library_facade
                  3rd party library dependencies

plugin
     my_plugin_shared_library (depends on main_shared library)

I have the majority of my main source code in a seperate library to allow me to link my plugins as dexribed in this thread: http://www.mail-archive.com/cmake@cmake.org/msg02810.html

I do not have direct control over the 3rd party libraries and there are also so some dependency problems which made me want to isolate those libraries.  So I wrote a facade library.

The plugin is an example to users of my application on how to extend my applications functionality.

I would like to just be able to distribute the main_exe, the plugin example, and the main shared library (to allow users to link the plugin).

Under cmake this is what currently happens:

- my_static_library_facade compiles, doesn't link 3rd party dependencies.
- main_shared_library compiles, links my_static_library, 3rd party libraries
- main_exe compiles, links my_shared_library, my_static_library, 3rd party  libraries
- plugin compiles,  links my_shared_library, my_static_library, 3rd party  libraries

My preference would be for the 3rd party libs to be linked when the facade library is created.  But even given that that can't happen under cmake, cmake unneccessarily links the libraries again when main_exe and the plugin is compiled.  This creates a unnecessary chain of dependencies.

BTW, if I read the documentation properly I believe LINK_LIBRARIES is the one that is deprecated not LINK_DIRECTORIES.

Thanks,

Bryan Walsh


---- Filipe Sousa <natros at gmail.com> wrote: 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> bpwlist at cox.net wrote:
> > Hi All,
> > 
> > I have a static library that I'm trying to compile and link under windows.  It depends on other static libraries.  It appears that the default behavior of cmake is to defer the linking of the dependencies until they are needed by a dll or executable.  There is no way under cmake that I have found to link the depedencies to the static library at time of creation.    Is this really the behavior that is desired?
> 
> I think this is the standard behavior.
> 
> > It appears that CMake ignores LINK_DIRECTORIES and TARGET_LINK_LIBRARIES when link the static library.  When the library is needed by a dll or executable the TARGET_LINK_LIBRARIES will be carried over but the user must specify the LINK_DIRECTORIES again.  The library that am I creating is suppose to be facade to the underlying dependencies so having to do this kind of defeats the purpose.  I have been able to do what I want with VS7 directly but haven't found a way to do this with cmake.
> 
> LINK_DIRECTORIES is deprecated
> 
> > Any ideas?
> 
> I don't see why this is problem. If you have libA, libB and libC (B
> depends on A and C depends on B) and you link the executable against C
> (TARGET_LINK_LIBRARIES(exe C) cmake knows that needs B and A and does
> that for you.
> 
> > Thanks for the help,
> > 
> > Bryan Walsh
> 
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
> 
> iD8DBQFGAb01bQdNYqwwwCwRAoWVAJ9RYeUS255myAcSnDtosmZowy5EMwCgnZNN
> zY+nh4NILIAzTDCQTaH5ZbE=
> =KR9M
> -----END PGP SIGNATURE-----
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake



More information about the CMake mailing list