我需要为一个项目包含GLib头文件,该项目是使用基于autoconf的系统构建的,以便于移植.
如何以可移植的方式安全地导入GLib标头?我知道pkg-config,但这不是完全可移植的(因为有些系统没有它,我宁愿只依靠autoconf进行配置).
我正在尝试使用这些头文件编译一个C程序:http://pastebin.com/SppCXb0U,在Ubuntu上.起初我根本没有任何运气,但在阅读了pkg-config之后我制作了这一行:
gcc `pkg-config --cflags --libs dbus-1` `pkg-config --cflags --libs glib-2.0` signals-tutorial.c
Run Code Online (Sandbox Code Playgroud)
但是,它仍然无法正常工作并给我这个错误:
/tmp/cc3BkbdA.o: In function `filter_example':
signals-tutorial.c:(.text+0x1a3): undefined reference to `dbus_connection_setup_with_g_main'
/tmp/cc3BkbdA.o: In function `proxy_example':
signals-tutorial.c:(.text+0x29a): undefined reference to `g_type_init'
signals-tutorial.c:(.text+0x2b3): undefined reference to `dbus_g_bus_get'
signals-tutorial.c:(.text+0x323): undefined reference to `dbus_g_proxy_new_for_name'
signals-tutorial.c:(.text+0x369): undefined reference to `dbus_g_proxy_add_signal'
signals-tutorial.c:(.text+0x38a): undefined reference to `dbus_g_proxy_connect_signal'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
我不知道该怎么做.
==================================
一个很好的解释 - 谢谢.但是,我无法让它发挥作用.在上面运行您的命令(添加)会产生以下结果
gcc `pkg-config --cflags dbus-1` \
> `pkg-config --cflags glib-2.0` \
> signals-tutorial.c \
> `pkg-config …Run Code Online (Sandbox Code Playgroud) 所以我正在为libgstreamermm-0.10编译示例,我遇到了CMake的问题.
使用我的系统上默认安装的libgstreamermm-0.10版本,示例为segfaults.好的,所以我获得了最新的源代码并将它们安装到/ usr/local并获得了新的示例.一切都很好看.
g++ main.cc player_window.cc -o test `pkg-config --cflags --libs gtkmm-3.0` `pkg-config --cflags --libs gstreamermm-0.10`
Run Code Online (Sandbox Code Playgroud)
工作正常,如预期的那样.很棒,现在尝试让它与CMake很好地配合.我制作了一个快速的CMakeLists.txt文件.我使用pkg-config,因为它工作正常,我真的不想添加一个find模块.所以我的文件看起来像这样:
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})
Run Code Online (Sandbox Code Playgroud)
一切都编译到链接阶段,在那里我得到未定义的符号错误.然后我pkg-config --libs gstreamermm-0.10用-L/usr/local/lib 查看start 的输出.我查看输出,make VERBOSE=1并且CMake没有在链接命令中添加-L,即使我有link_directories行.所以,即使我在/ usr/local/include中使用新版gstreamer的头文件,但是当我想要使用/ usr/local/lib中的版本时,正在使用来自/ usr/lib的库. .Pkg-Config似乎已经接受了这一点,并相应地进行了调整,但是CMake,即使我在内部使用pkg-config,也没有接收到链接标志.
我现在可以手动设置链接标志,但这似乎有点像黑客.我确信有更好的方法来指定它.
许多makefile使用pkg-config,但名称与包管理器无关(例如yum/apt).如何将pkg-config名称映射到它们?有诀窍吗?
示例:如果我这样做yum searchName- 查看名称并接近pkg-config的名称
结果:
$ pkg-config --libs dbus-glib-0
Package dbus-glib-0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `dbus-glib-0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'dbus-glib-0' found
$ sudo yum install dbus-glib
Loaded plugins: langpacks, refresh-packagekit
Package dbus-glib-0.100-5.fc19.i686 already installed and latest version
Nothing to do
$ sudo yum install dbus-glib-0
Loaded plugins: langpacks, refresh-packagekit
No package dbus-glib-0 available.
Error: Nothing to do
Run Code Online (Sandbox Code Playgroud) 我试图在R版本3.2.1中安装devtools,但是当我这样做时会抛出以下错误:
Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing libxml-2.0.pc
to the PKG_CONFIG_PATH environment variable
Run Code Online (Sandbox Code Playgroud)
当我dpkg -L libxml2-dev在终端中运行时,我发现:
/usr
/usr/bin
/usr/bin/xml2-config
/usr/share
/usr/share/aclocal
/usr/share/aclocal/libxml2.m4
/usr/share/doc
/usr/share/doc/libxml2-dev
/usr/share/doc/libxml2-dev/copyright
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/xml2-config.1.gz
/usr/share/man/man3
/usr/share/man/man3/libxml.3.gz
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libxml2.a
/usr/lib/x86_64-linux-gnu/pkgconfig
/usr/lib/x86_64-linux-gnu/pkgconfig/libxml-2.0.pc
/usr/lib/x86_64-linux-gnu/xml2Conf.sh
/usr/include
/usr/include/libxml2
/usr/include/libxml2/libxml
/usr/include/libxml2/libxml/globals.h
/usr/include/libxml2/libxml/schematron.h
/usr/include/libxml2/libxml/xlink.h
/usr/include/libxml2/libxml/HTMLparser.h
/usr/include/libxml2/libxml/pattern.h
/usr/include/libxml2/libxml/xmlexports.h
/usr/include/libxml2/libxml/xmlschemas.h
/usr/include/libxml2/libxml/list.h
/usr/include/libxml2/libxml/entities.h
/usr/include/libxml2/libxml/xmlstring.h
/usr/include/libxml2/libxml/encoding.h
/usr/include/libxml2/libxml/hash.h
/usr/include/libxml2/libxml/xmlmemory.h
/usr/include/libxml2/libxml/relaxng.h
/usr/include/libxml2/libxml/xmlsave.h
/usr/include/libxml2/libxml/SAX2.h
/usr/include/libxml2/libxml/xmlIO.h
/usr/include/libxml2/libxml/xmlschemastypes.h
/usr/include/libxml2/libxml/xpathInternals.h
/usr/include/libxml2/libxml/schemasInternals.h
/usr/include/libxml2/libxml/xmlmodule.h
/usr/include/libxml2/libxml/valid.h
/usr/include/libxml2/libxml/c14n.h
/usr/include/libxml2/libxml/xmlwriter.h
/usr/include/libxml2/libxml/tree.h
/usr/include/libxml2/libxml/xmlunicode.h
/usr/include/libxml2/libxml/nanohttp.h
/usr/include/libxml2/libxml/catalog.h …Run Code Online (Sandbox Code Playgroud) 我想从目标生成cmake中的pkgconfig文件.我盯着写下这样的东西:
function(auto_pkgconfig TARGET)
get_target_property(INCLUDE_DIRS ${TARGET} INTERFACE_INCLUDE_DIRECTORIES)
string(REPLACE "$<BUILD_INTERFACE:" "$<0:" INCLUDE_DIRS "${INCLUDE_DIRS}")
string(REPLACE "$<INSTALL_INTERFACE:" "$<1:" INCLUDE_DIRS "${INCLUDE_DIRS}")
string(REPLACE "$<INSTALL_PREFIX>" "${CMAKE_INSTALL_PREFIX}" INCLUDE_DIRS "${INCLUDE_DIRS}")
file(GENERATE OUTPUT ${TARGET}.pc CONTENT "
Name: ${TARGET}
Cflags: -I$<JOIN:${INCLUDE_DIRS}, -I>
Libs: -L${CMAKE_INSTALL_PREFIX}/lib -l${TARGET}
")
install(FILES ${TARGET}.pc DESTINATION lib/pkgconfig)
endfunction()
Run Code Online (Sandbox Code Playgroud)
这是一个简化版本,但它基本上读取INTERFACE_INCLUDE_DIRECTORIES属性并处理INSTALL_INTERFACE生成器表达式.只要在调用之前设置了include目录,这样就可以正常工作auto_pkgconfig,如下所示:
add_library(foo foo.cpp)
target_include_directories(foo PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>
${OTHER_INCLUDE_DIRS}
)
auto_pkgconfig(foo)
Run Code Online (Sandbox Code Playgroud)
但是,有时会在调用之后设置属性auto_pkgconfig,如下所示:
add_library(foo foo.cpp)
auto_pkgconfig(foo)
target_include_directories(foo PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/include>
${OTHER_INCLUDE_DIRS}
)
Run Code Online (Sandbox Code Playgroud)
但是,这将无法正确读取包含目录.我希望auto_pkgconfig在设置所有目标属性后运行.我可以使用生成器表达式,通过更改auto_pkgconfig为:
function(auto_pkgconfig TARGET)
file(GENERATE OUTPUT ${TARGET}.pc CONTENT " …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Win10 上使用 x265 编译 FFMPEG。我正在使用来自 xhmikosr 的最新完整 MinGW 构建:
http://xhmikosr.1f0.de/tools/msys/
Run Code Online (Sandbox Code Playgroud)
没有 x265 的 FFMEPG 编译没有问题,编译 x265 独立工作也没有问题。但是,当我在 ffmpeg 中 --enable-libx265 时出现以下错误:
ERROR: x265 not found using pkg-config
Run Code Online (Sandbox Code Playgroud)
这来自 config.log:
require_pkg_config libx265 x265 x265.h x265_api_get
check_pkg_config libx265 x265 x265.h x265_api_get
test_pkg_config libx265 x265 x265.h x265_api_get
false --exists --print-errors x265
ERROR: x265 not found using pkg-config
Run Code Online (Sandbox Code Playgroud)
我的配置路径似乎都设置正确。
$ echo $PKG_CONFIG_PATH
C:\MYSYS\local\x86_64-w64-mingw32\lib\pkgconfig
Run Code Online (Sandbox Code Playgroud)
当我寻找库 x265 时:
$ pkg-config --list-all
...
x265 x265 - H.265/HEVC video encoder
...
Run Code Online (Sandbox Code Playgroud)
和这里的调试日志:
$ pkg-config --debug
...
File …Run Code Online (Sandbox Code Playgroud) 我编写了一个小型库,并尝试将其设置为可与 pkg-config 一起使用,以供我组织中稍后可能需要使用它的人员使用。因此,我的安装程序将一个 .pc 文件放在 /usr/local/lib/pkgconfig 中,并且我最近发现,由于某种原因,该文件不在 pkg-config 扫描其 pc 文件的默认目录列表中,尽管 / usr/local 是本地编译软件的规范前缀。因此,我需要将 /usr/local/lib/pkgconfig 添加到 PKG_CONFIG_PATH 中。
然而,我发现尽管手册页、pkg-config 自己的错误消息以及网上到处都有这样的声明,pkg-config 实际上并不查看 PKG_CONFIG_PATH。错误消息告诉我将 /usr/local/lib/pkgconfig (其中包含我正在查找的 .pc 文件)添加到 PKG_CONFIG_PATH 中,而我显然已经这样做了。
[chris@delphinus-a pkgconfig]$ pwd
/usr/local/lib/pkgconfig
[chris@delphinus-a pkgconfig]$ ls
libexample.pc
[chris@delphinus-a pkgconfig]$ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
[chris@delphinus-a pkgconfig]$ echo $PKG_CONFIG_PATH
/usr/local/lib/pkgconfig
[chris@delphinus-a pkgconfig]$ pkg-config --cflags libexample
Package libexample was not found in the pkg-config search path.
Perhaps you should add the directory containing `libexample.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libexample', required by 'virtual:world', not found …Run Code Online (Sandbox Code Playgroud) 尝试从 mac 编译 linux 会引发此错误,我已经从brew安装了openssl和pkg-config。
在文件 ~/.cargo/config 中我有这个配置。
[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-musl-gcc"
Run Code Online (Sandbox Code Playgroud)
错误:
error: failed to run custom build command for `openssl-sys v0.9.72`
Caused by:
process didn't exit successfully: `/Users/Proyect/cvm/target/release/build/openssl-sys-66182f9fe15cdddc/build-script-main` (exit status: 101)
run pkg_config fail: "`\"pkg-config\" \"--libs\" \"--cflags\" \"openssl\"` did not exit successfully: exit status: 1\nerror: could not find system library 'openssl' required by the 'openssl-sys' crate\n\n--- stderr\nPackage openssl was not found in the pkg-config search path.\nPerhaps you should add the directory containing `openssl.pc'\nto …Run Code Online (Sandbox Code Playgroud) 我一直在尝试在 mac os x 上安装 pycairo。我收到一条错误消息,
最初我得到了'pkg-config' not found。通过brew安装后,我得到了Package cairo was not found in the pkg-config search path。原则上我可以尝试编辑搜索路径,但由于这是通过 pip 进行的,所以我希望这一切都能得到解决。有没有办法告诉 pip 将内容放在 pkg-config 知道要查找的地方?
这是完整的消息。
> pip install pycairo
Collecting pycairo
Using cached https://files.pythonhosted.org/packages/48/20/5e83af98eb897935bf7dc39455e892ba866feebb9b7c3b392982866f9958/pycairo-1.18.1.tar.gz
Building wheels for collected packages: pycairo
Building wheel for pycairo (setup.py) ... error
ERROR: Complete output from command /Applications/anaconda/bin/python -u -c 'import setuptools, tokenize;__file__='"'"'/private/var/folders/f2/bzrj46j11gzdk19j91tp1sq80000gq/T/pip-install-lahb8lq4/pycairo/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/f2/bzrj46j11gzdk19j91tp1sq80000gq/T/pip-wheel-scnvplas --python-tag cp36:
ERROR: running bdist_wheel
running build
running build_py
creating …Run Code Online (Sandbox Code Playgroud)