[CMake] Object file as first one in link.txt file

Rolf Eike Beer eike at sf-mail.de
Thu Oct 17 06:32:45 EDT 2013


Am 17.10.2013 12:00, schrieb Juan Pablo Hernandez Vogt:
> Hello everybody,
> 
> I moving a makefile to cmake, and after errors I could check that order 
> in
> link chain was important.
> 
> 1) CMake generates this link.txt (error when linking)
> /usr/bin/c++       -lfusion_io -ladios -lmxml -lmpi -lopen-rte 
> -lopen-pal
> -lpthread -lstdc++ CMakeFiles/niio-main.dir/main.cpp.o  -o niio-main
> -rdynamic -L/home/testuser/dev/niio/lib
> -L/home/testuser/dev/niio/openmpi/lib
> 
> 
> 2) Desired linking that works:
> /usr/bin/c++       CMakeFiles/niio-main.dir/main.cpp.o -lfusion_io 
> -ladios
> -lmxml -lmpi -lopen-rte -lopen-pal -lpthread -lstdc++   -o niio-main
> -rdynamic -L/home/testuser/dev/niio/lib
> -L/home/testuser/dev/niio/openmpi/lib
> 
> 
> My question is, how to fix in my CMakeLists.txt to have main.cpp.o 
> first in
> the sequence of the link command?
> 
> 
> My current code is:
> 
> set(TARGET_NAME "niio-main")
> 
> link_directories("${PROJECT_SOURCE_DIR}/lib")
> link_directories("${PROJECT_SOURCE_DIR}/openmpi/lib")
> 
> add_executable(${TARGET_NAME} main.cpp)
> 
> include_directories("${PROJECT_SOURCE_DIR}")
> include_directories("${PROJECT_SOURCE_DIR}/openmpi/include")
> 
> add_definitions( -DOMPI_SKIP_MPICXX -DDEBUG -DNI_IO -DNI_MPI )
> 
> set_target_properties(${TARGET_NAME} PROPERTIES COMPILE_FLAGS "-fPIC -g
> -Wall -Wno-deprecated")
> 
> set_target_properties(${TARGET_NAME} PROPERTIES LINK_FLAGS "-lfusion_io
> -ladios -lmxml -lmpi -lopen-rte -lopen-pal -lpthread -lstdc++")

cmake --help-module FindMPI
cmake --help-module FindThreads (I doubt you need it, this is probably 
only a dependency of MPI which should take care for that itself)
cmake --help-command link_directories

To get -g: cmake -D CMAKE_BUILD_TYPE=Debug … (or =RelWithDebInfo).

Eike


More information about the CMake mailing list