undefined reference to `shm_open' using CMake

余生长醉 提交于 2020-01-03 17:41:07

问题


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.


回答1:


You need to add rt in TARGET_LINK_LIBRARIES as a last one, for example:

TARGET_LINK_LIBRARIES(my_app ${Boost_LIBRARIES} rt)

You can verify position of rt by enabling verbose build output:

SET (CMAKE_VERBOSE_MAKEFILE 1)


来源:https://stackoverflow.com/questions/31147129/undefined-reference-to-shm-open-using-cmake

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!