[CMake] A problem about linking libraries

Alexander Neundorf a.neundorf-work at gmx.net
Tue Apr 26 02:07:49 EDT 2005


> Hi all, 
>  
> I have a problem about linking libraries. 
>  
> In my program, I have to use the Cppunit library. 
>  
> The content of the CMakeLists.txt is below. 
>  
> --- 
> PROJECT(testing) 
>  
> ADD_EXECUTABLE(main main.cpp HelloCPPUnitTest.cpp ) 
>  
> FIND_LIBRARY(CPPUNIT_LIBARY NAMES cppunit 
> PATHS /usr/lib /usr/local/lib) 
> IF (CPPUNIT_LIBRARY) 
> ADD_LIBRARY(CPPUNIT_LIBRARY) 
> LINK_LIBRARIES(cppunit) 
> ENDIF (CPPUNIT_LIBRARY) 
 
ADD_LIBRARY creates a new library. LINK_LIBRARIES is more or less 
deprecated. So how about the following: 
 
PROJECT(testing) 
 
ADD_EXECUTABLE(main main.cpp HelloCPPUnitTest.cpp ) 
 
FIND_LIBRARY(CPPUNIT_LIBARY NAMES cppunit 
  PATHS /usr/lib /usr/local/lib) 
IF (CPPUNIT_LIBRARY) 
  TARGET_LINK_LIBRARY(main ${CPPUNIT_LIBRARY}) 
ENDIF (CPPUNIT_LIBRARY) 
 
Bye 
Alex 
 

-- 
+++ Sparen beginnt mit GMX DSL: http://www.gmx.net/de/go/dsl


More information about the CMake mailing list