[CMake] Linking Problems when using Cmake
David Cole
david.cole at kitware.com
Wed Jun 29 11:34:21 EDT 2005
Aren't both netapi32 and wsock32 Windows only libraries? You shouldn't
even have them in your Linux link at all. Try removing them - you can
conditionally add them by setting them into a CMake variable (when WIN32
is true) and using that variable in the TARGET_LINK_LIBRARIES command.
Something like this:
IF(WIN32)
SET(OS_SPECIFIC_LIBS netapi32 wsock32)
ELSE(WIN32)
SET(OS_SPECIFIC_LIBS )
ENDIF(WIN32)
...
TARGET_LINK_LIBRARIES(
...
${OS_SPECIFIC_LIBS}
...
)
HTH,
David
Dalal, Dhaval wrote:
>Hi Everyone
>I am trying to compile Dcmtk(open-source Dicom Library), ITK and FLTK on my Linux Platform
>(gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-52))
>I got them successfulle compiled on the Windows Platform but I am facing strage errors on Linux and I have been unable to fix them.
>I have checked the order of libraries (in the way they are linked to the executable) and
>also tweaked around quite a bit but to no awail.
>The error i get is
>"Building executable /usr/local/gui/ti...
>/usr/bin/ld: cannot find -lnetapi32
>collect2: ld returned 1 exit status
>make[1]: *** [/usr/local/gui/ti] Error 1"
>
>My CMakeLists.txt file is
>------------------------------------------------------------
>PROJECT(DCMTKTEST)
>
>
>
>FIND_PACKAGE(DCMTK)
>
>FIND_PACKAGE(ZLIB)
>
>
> #Find ITK.
>
>FIND_PACKAGE(ITK)
>
>IF(ITK_FOUND)
>
> INCLUDE(${ITK_USE_FILE})
>
>ELSE(ITK_FOUND)
>
> MESSAGE( FATAL_ERROR
>"Cannot build without ITK. Please set ITK_DIR.")
>
>ENDIF(ITK_FOUND)
>
>
>
>
>
># Make sure the compiler can find include files from our library.
>
>INCLUDE_DIRECTORIES(
> ${DCMTK_DIR}/imagectn/include
> ${DCMTK_ofstd_INCLUDE_DIR}
>
> ${DCMTK_config_INCLUDE_DIR}
>
> ${DCMTK_dcmdata_INCLUDE_DIR}
> ${DCMTK_DIR}/dcmnet/include
>
> ${DCMTK_dcmingle_INCLUDE_DIR}
>
> )
>
>
>
># set certain project wide flags
>
>#SET(CMAKE_C_FLAGS "" CACHE STRING "Flags for C compiler." FORCE)
>
>#SET(CMAKE_C_FLAGS_DEBUG "/nologo /MDd /W3 /GX /Z7 /Od /GR /YX " CACHE STRING "Win32 Debug Options #C Code" FORCE)
>
>#SET(CMAKE_C_FLAGS_RELEASE "/nologo /MD /W3 /GX /O2 /GR /YX" CACHE STRING "Win32 Release Options C #Code" FORCE)
>
>#SET(CMAKE_CXX_FLAGS "" CACHE STRING "Flags used by the compiler during all build types." FORCE)
>
>#SET(CMAKE_CXX_FLAGS_DEBUG "/nologo /MDd /W3 /GX /Z7 /Od /GR /YX" CACHE STRING "Win32 Debug #Options C++ Code" FORCE)
>
>#SET(CMAKE_CXX_FLAGS_RELEASE "/nologo /MD /W3 /GX /O2 /GR /YX" CACHE STRING "Win32 Release Options #C++ Code" FORCE)
>
>#SET(CMAKE_EXE_LINKER_FLAGS "/INCREMENTAL:NO" CACHE STRING "Win32 Linker Flags" FORCE)
>
>
>
>FIND_LIBRARY(DCMTK_imagedb_LIBRARY libimagedb ${DCMTK_DIR}/imagectn/libsrc)
>
>FIND_LIBRARY(DCMTK_dcmnet_LIBRARY dcmnet ${DCMTK_DIR}/dcmnet/libsrc)
>
>
>
>
>
># set _REENTRANT flag
>
>ADD_DEFINITIONS(-D_REENTRANT)
>
>ADD_DEFINITIONS(-DHAVE_CONFIG_H)
>
>
>
>
>
>INCLUDE(${CMAKE_ROOT}/Modules/FindFLTK.cmake)
>
>IF(HAS_FLTK)
>
> INCLUDE_DIRECTORIES(
>
> ${FLTK_INCLUDE_DIR}
>
> )
>
> LINK_LIBRARIES(
>
> ${FLTK_LIBRARIES}
>
> )
>
>ENDIF(HAS_FLTK)
>
>
>
>INCLUDE_DIRECTORIES(
>
> ${DCMTKTEST_SOURCE_DIR}
>
> ${DCMTKTEST_BINARY_DIR}
>
> )
>
>
>
>#IF(CYGWIN)
>
># LINK_LIBRARIES(ole32 uuid comctl32 wsock32 supc++ -lm -lgdi32)
>
>#ENDIF(CYGWIN)
>
>
>
>SET( DCMTK_GUI_SRCS
>
> dcmtkui.fl
>
> prefsui.fl
>
> )
>
>
>
>IF(FLTK_WRAP_UI)
>
> FLTK_WRAP_UI(ti ${DCMTK_GUI_SRCS})
>
> ENDIF(FLTK_WRAP_UI)
>
>
>
>SET(DCMTKTEST_SRCS
>
> cnf.h
>
> cnf.cxx
>
> cnfexnt.cxx
>
> cnfpriv.cxx
>
> cnfpriv.h
> main.cpp
>
> ti.cxx
>
> ti.h
>
> tinet.cxx
>
> tinet.h
>
> tiquery.cxx
>
> tiquery.h
>
> tiui.cxx
>
> tiui.h
>
> prefs.h
>
> prefs.cpp
>
> dcmtk.h
>
> dcmtk.cpp
>
> )
>
>
>
>ADD_EXECUTABLE( ti ${DCMTKTEST_SRCS} )
>
>
>
>
>
> TARGET_LINK_LIBRARIES(
>
> ti
>
> netapi32
> wsock32
> ${DCMTK_ofstd_LIBRARY}
> ${DCMTK_dcmdata_LIBRARY}
> ${DCMTK_dcmnet_LIBRARY}
> ${DCMTK_imagedb_LIBRARY}
>
> ${DCMTK_dcmimgle_LIBRARY}
> ${ZLIB_LIBRARY}
> # ITKCommon
>
> )
>------------------------------------------------------
> If i change the order , like
> TARGET_LINK_LIBRARIES(
> ti
> wsock32
> netapi32
> ${DCMTK_ofstd_LIBRARY}
> ${DCMTK_dcmdata_LIBRARY}
> ${DCMTK_dcmnet_LIBRARY}
> ${DCMTK_imagedb_LIBRARY}
> ${DCMTK_dcmimgle_LIBRARY}
> ${ZLIB_LIBRARY}
> # ITKCommon
> )
>
>I get the following error
>"Building dependencies. cmake.depends...
>Building executable /usr/local/gui/ti...
>/usr/bin/ld: cannot find -lwsock32
>collect2: ld returned 1 exit status"
>
>I am sure its some linking problem...
>any help/hints will be greatly appreciated.
>Thanks
>Dhaval
>
>_______________________________________________
>CMake mailing list
>CMake at cmake.org
>http://www.cmake.org/mailman/listinfo/cmake
>
>
>
More information about the CMake
mailing list