使用CMake对`shm_open'的未定义引用 [英] undefined reference to `shm_open' using CMake

查看:2192
本文介绍了使用CMake对`shm_open'的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Ubuntu 14.04下使用CMake来配置我的项目。
我需要使用第三方库(比如stuff.so)。
在CMakeLists.txt中,我使用TARGET_LINK_LIBRARIES链接资料库。
然而,我得到一个错误:

lockquote
DIR_TO_LIB / stuff.so:-1:error:undefined reference to`shm_open'


我试图将这些标记放在CMakeLists.txt中,但它不起作用:

  set(CMAKE_EXE_LINKER_FLAGS$ {CMAKE_EXE_LINKER_FLAGS} -lrt)
set(CMAKE_CXX_FLAGS$ {CMAKE_CXX_FLAGS} -lrt)

一篇文章( link )表示-lrt应该作为g ++的最后一个参数。在我使用CMake的情况下,我该怎么做?

更新
我加了


$ b $

  SET(CMAKE_VERBOSE_MAKEFILE 1)



<我发现-lrt不是最后一个(即使我把它放在目标链接的末尾)。请参阅链接以获得编译输出。



正如你从编译输出中看到的那样,opencv有一些链接标志。
我不明白这是怎么会发生的,因为我先在TARGET_LINK_LIBRARIES中链接OpenCV库。 CMake如何处理这些链接命令?



请参阅我的 CMakeLists.txt



谢谢。

解决方案

您需要在 TARGET_LINK_LIBRARIES 中添加 rt 作为最后一个,例如:

  TARGET_LINK_LIBRARIES(my_app $ {Boost_LIBRARIES} rt)

您可以通过启用详细的构建输出来验证 rt 的位置:

  SET(CMAKE_VERBOSE_MAKEFILE 1)


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.

解决方案

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)

这篇关于使用CMake对`shm_open'的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆