CMake Pkg-Config库链接路径 [英] CMake Pkg-Config Library Link Path

查看:1549
本文介绍了CMake Pkg-Config库链接路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我编译libgstreamermm-0.10的例子,我遇到了一个CMake的问题。

So I'm compiling the examples for libgstreamermm-0.10, and I've run into an issue with CMake.

libgstreamermm-0.10的版本是默认安装在我的系统上,例如segfaults。 OK,所以我得到最新的源,并安装他们到/ usr / local和得到新的例子。一切都很好。

With the version of libgstreamermm-0.10 that is installed by default on my system, the example segfaults. OK, so I got the latest sources and installed them to /usr/local and get the new example. Everything's looking good.

g++ main.cc player_window.cc -o test `pkg-config --cflags --libs gtkmm-3.0` `pkg-config --cflags --libs gstreamermm-0.10`

。伟大的,现在尝试,并得到它与CMake发挥得很好。我制作一个快速CMakeLists.txt文件。我使用pkg-config,因为工作正常,我不真的想添加一个查找模块。所以我的文件看起来像这样:

works fine and as expected. Great, now to try and get it to play nicely with CMake. I make a quick CMakeLists.txt file. I use pkg-config, as that worked fine and I don't really want to add a find module. So my file looks like this:

cmake_minimum_required(VERSION 2.6.2)
project(media_player_gtkmm)

INCLUDE(FindPkgConfig)

set(SOURCES main.cc player_window.cc)

add_executable(media_player_gtkmm ${SOURCES})

#dependencies
pkg_check_modules(GSTMM REQUIRED gstreamermm-0.10)
pkg_check_modules(GTKMM REQUIRED gtkmm-3.0)
include_directories(${GTKMM_INCLUDE_DIRS} ${GSTMM_INCLUDE_DIRS})
link_directories(${GTKMM_LIBRARY_DIRS} ${GSTMM_LIBRARY_DIRS})
target_link_libraries(media_player_gtkmm ${GTKMM_LIBRARIES} ${GSTMM_LIBRARIES})

所有的编译直到链接阶段,其中我得到未定义的符号错误。然后我看到 pkg-config --libs gstreamermm-0.10 的输出以-L / usr / local / lib开头。我看看 make VERBOSE = 1 的输出,并且CMake没有添加-L到链接命令,即使我有link_directories行。因此,即使我在/ usr / local / include中使用了gstreamer的新版本的头文件,也会使用/ usr / lib中的库文件,当我想使用/ usr / local / lib中的版本。 Pkg-Config似乎在这一点上,并相应地进行调整,但CMake,即使我有它使用pkg-config内部,不拾取的链接标志。

Everything compiles until the link stage, where I get undefined symbol errors. I then see the output of pkg-config --libs gstreamermm-0.10 starts with -L/usr/local/lib. I look at the output of make VERBOSE=1 and CMake is NOT adding the -L to the link command, even though I have the link_directories line. So even though I'm using the headers for the new version of gstreamer in /usr/local/include, the library from /usr/lib is being used instead, when I want the version in /usr/local/lib to be used. Pkg-Config seems to pick up on this, and adjusts accordingly, but CMake, even though I have it using pkg-config internally, doesn't pick up on the link flags.

我可以手动设置链接标志,但现在似乎有点黑客。我确定有更好的方法来指定这个。

I could manually set the link flags for now, but that seems like a bit of a hack. I'm sure there's a better way to specify this.

推荐答案

link_directories 仅影响之后的目标。因此,您需要
add_executable 移动到 link_directories 调用之后。

link_directories only affects targets that come AFTER it. So, you need to move your add_executable to be after the link_directories call.

这篇关于CMake Pkg-Config库链接路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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