【发布时间】:2019-01-07 23:57:57
【问题描述】:
我有以下(最小)CMakeLists.txt 应该通过pkg-config 找到 GLib 并将这些库添加到 foo 目标:
cmake_minimum_required(VERSION 2.10 FATAL_ERROR)
project(foo)
find_package(PkgConfig REQUIRED)
pkg_check_modules(GLib REQUIRED glib-2.0)
add_executable(foo foo.cpp)
message(WARNING "libs:" ${GLIB_LIBRARIES})
message(WARNING "includes:" ${GLIB_INCLUDE_DIRS})
target_link_libraries(foo PUBLIC ${GLIB_LIBRARIES})
target_include_directories(foo PUBLIC ${GLIB_INCLUDE_DIRS})
无论我尝试什么,我都会得到(注意Found glib-2.0 部分):
-- The C compiler identification is GNU 7.3.0
-- The CXX compiler identification is GNU 7.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
-- Checking for module 'glib-2.0'
-- Found glib-2.0, version 2.56.1
CMake Warning at CMakeLists.txt:6 (message):
libs:
CMake Warning at CMakeLists.txt:7 (message):
includes:
CMake Error at CMakeLists.txt:9 (target_include_directories):
target_include_directories called with invalid arguments
-- Configuring incomplete, errors occurred!
See also "/tmp/aaa/CMakeFiles/CMakeOutput.log".
我看不到,阅读the CMake reference 哪些参数无效(注意:这个问题与cmake target_include_directories called with invalid arguments 不同)。我还查看了CMake's FindPkgConfig documentation,它以glib 为例,但我无法重现它(${GLIB_VERSION})。我尝试了 GLIB_ 和 GLIB2_ 前缀,但得到的只是空字符串。
尽管pkg-config 正确报告了值,但消息显示变量为空:
$ pkg-config glib-2.0 --cflags --libs
-I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -lglib-2.0
我的 CMake 版本是 2.10。
有人能解释一下这个问题吗?
【问题讨论】:
-
${GLIB_INCLUDE_DIRS}有值吗?message()将这些变量打印到控制台的内容是什么? -
@compor 我在问题中添加了来自
pkg-config的消息和输出。 -
变量是空的,所以我认为这是@mshildt 在他的回答中所建议的。