[CMake] Why does Cmake never add libs when it comes to static linking?

Bill Hoffman bill.hoffman at kitware.com
Mon Jun 22 12:11:21 EDT 2009


ariasgore at gmx.de wrote:
> Hello,
> I have some code that uses some libs in the following defined vars:
> 
> # -------------------------------------------------------------------------
> # Add everything into executable
> # -------------------------------------------------------------------------
> ADD_LIBRARY(${PROJECTNAME1} ${sources} ${includes} ${vectors} )
> 
> # ----------------------------------------------------------------------------
> # Link libraries
> # ----------------------------------------------------------------------------
> TARGET_LINK_LIBRARIES ( ${PROJECTNAME1}  
> 			${OPENSCENEGRAPH_LIBRARIES}
> 			${OSG_LIBRARY}
> )
> 
> If I build this as a shared library (e.g. DLL) I can see in the linker settings all mentioned libraries with TARGET_LINK_LIBRARIES, that is fine.
> But when I build a static library, none of the linked libraries occur in the /IMPLIB dialog. To be precisely they occur nowhere! So where do they vanish?
> I am quite desperate about that.
> 

Static libraries do not link to other static libraries.  However, CMake 
will automatically use them for executables.

add_executable(foo ${foo_sources})
target_link_libraries(foo ${PROJECTNAME1})

Then foo will link to all the libraries you listed 
(${OPENSCENEGRAPH_LIBRARIES} ${OSG_LIBRARY}.

-Bill


More information about the CMake mailing list