I am using CMake under Ubuntu 14.04 to configure my project.
I need to use a 3rd party library (say stuff.so).
In the CMakeLists.txt, I use TARGET_LINK_LIBRARIES to link the stuff library.
However, I got an error:
DIR_TO_LIB/stuff.so:-1: error: undefined reference to `shm_open'
I tried to put these flag in the CMakeLists.txt but it didn't work:
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lrt")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lrt")
A post (link) saying that -lrt should be put as the last argument of g++. In my case where CMake is used, how shall I do this?
UPDATE:
I added
SET (CMAKE_VERBOSE_MAKEFILE 1)
and I found that -lrt is not the last (even though I put it at the end of the target link). Please see this link for compile output.
As you can see from the compile output, there are some linking flags for the opencv.
I don't understand how could this happen as I link the OpenCV library first in the TARGET_LINK_LIBRARIES. How does CMake handle these linking order?
Please also see my CMakeLists.txt.
Thank you.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…