[CMake] LINK_DIRECTORIES gives errors

Bill Hoffman bill.hoffman at kitware.com
Tue May 29 10:27:20 EDT 2007


abhijeet mhatre wrote:
> Hi  list
>   I am using cmake as a tool for generating Linux makefiles.
>
> I read the documentation and made a CmakeLists.txt file.
> but when I do a cmake . , I get  errors
>
> here is the CmakeLists.txt file
> ----------------------
> PROJECT(myproject)
> SET_TARGET_PROPERTIES(HelloWorld PROPERTIES LINKER_LANGUAGE CXX)
> INCLUDE_DIRECTORIES(../dcmtk-3.5.4/dcmnet/apps  
> ../dcmtk-3.5.4/dcmnet/include ../dcmtk-3.5.4/dcmdata/include 
> ../dcmtk-3.5.4/dcmdata ../dcmtk-3.5.4/ofstd/include 
> ../dcmtk-3.5.4/config/include)
> ADD_DEFINITIONS(-DHAVE_CONFIG_H -DNDEBUG -D_REENTRANT 
> -D_XOPEN_SOURCE_EXTENDED -D_XOPEN_SOURCE=500 -D_BSD_SOURCE 
> -D_BSD_COMPAT -D_OSF_SOURCE -D_POSIX_C_SOURCE=199506L)
> LINK_DIRECTORIES(../dcmtk-3.5.4/dcmnet/libsrc 
> ../dcmtk-3.5.4/dcmdata/libsrc ../dcmtk-3.5.4/ofstd/libsrc 
> ../dcmtk-3.5.4/dcmtls/libsrc)
> TARGET_LINK_LIBRARIES(HelloWorld dcmnet dcmdata ofstd z wrap dcmtls dl 
> m rt pthread nsl)
> ADD_EXECUTABLE(HelloWorld HelloWorld.cpp)
> --------------------
>
> and here are the errors
> --------------------
> CMake Error: Attempt to add link library "dcmnet" to target 
> "HelloWorld" which is not built by this project.
> CMake Error: Attempt to add link library "dcmdata" to target 
> "HelloWorld" which is not built by this project.
> ....
> ---------------------
>
> Agreed that I am linking to a library that's not built by CMake. But 
> shouldn't I be allowed to do it?
Actually, it is trying to say that target "HelloWorld" is not built by 
the project.   The TARGET_LINK_LIBRARIES command must come AFTER the 
ADD_EXECUTABLE command so that cmake will know what the target is.

-Bill



More information about the CMake mailing list