Linux 如何在 pkg-config 中使用 C++ Boost 库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3971703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 23:43:56  来源:igfitidea点击:

How to use C++ Boost library with pkg-config?

c++linuxunixboostpkg-config

提问by eold

I successfully compiled and installed the latest version of the Boost library onto my linux machine. Now, I would like to be able to use pkg-config to ease the process of providing linking paremeters with GCC.

我成功地编译并安装了最新版本的 Boost 库到我的 linux 机器上。现在,我希望能够使用 pkg-config 来简化使用 GCC 提供链接参数的过程。

Since I am too lazy for hand-coding my own .pc file, is there a script/tool which would automatically generate the needed .pc file or in some other way update pkg-config with boost flags?

由于我懒得手动编码我自己的 .pc 文件,是否有脚本/工具可以自动生成所需的 .pc 文件或以其他方式使用 boost 标志更新 pkg-config ?

(If someone already has that .pc file, a share would be welcome as well.)

(如果有人已经拥有该 .pc 文件,也欢迎分享。)

采纳答案by amireh

What you're looking for seems to be a bit complicated, and a long-requested feature, as indicated in this 3 year old post https://svn.boost.org/trac/boost/ticket/1094on Boost's trac. Reading through it shows that the feature was repeatedly postponed and never implemented (as of 1.4.3). The cause of the inability to generate a .pc file usable by pkg-config happens to do with boost's inconsistency in naming their library versions / build variants.

您正在寻找的东西似乎有点复杂,而且是一项长期要求的功能,如Boost 的trac上这篇 3 年前的帖子https://svn.boost.org/trac/boost/ticket/1094 所示。通读它表明该功能被反复推迟并且从未实现(从 1.4.3 开始)。无法生成可由 pkg-config 使用的 .pc 文件的原因恰好与 boost 在命名其库版本/构建变体方面的不一致有关。

FWIW, an alternative for "automating" your building process is to use autotools (autoconf/automake). There's a link that might be of use to you (which I can't post because SO thinks I'm a spammer instead of a newcomer!), just google "tsuna boost m4 github" and it should take you there :)

FWIW,“自动化”构建过程的另一种选择是使用自动工具(autoconf/automake)。有一个链接可能对你有用(我不能发布,因为我认为我是垃圾邮件发送者而不是新人!),只需谷歌“tsuna boost m4 github”,它应该带你去那里:)

回答by nmante

Was facing a similar issue with boost. Wrote simple python script to generate a .pc file. Saved me the pain of having write all the linker commands. I've posted it on https://github.com/nmante/pkg-config-generator.

正面临着与 boost 类似的问题。编写简单的 python 脚本来生成 .pc 文件。让我省去了编写所有链接器命令的痛苦。我已将其发布在https://github.com/nmante/pkg-config-generator 上

Essentially, you give the script a directory where the library files are (.so, .a, .dylib files) and it will generate the linker commands (e.g. -lboost_graph). Feel free to tweak and fork to your needs.

本质上,您为脚本提供了一个库文件所在的目录(.so、.a、.dylib 文件),它将生成链接器命令(例如 -lboost_graph)。随意调整和分叉您的需求。

Here's a sample boost.pc file I generated for my machine (Mac OS X). You can tweak it manually, or you can use my github programto generate it on your machine.

这是我为我的机器 (Mac OS X) 生成的示例 boost.pc 文件。您可以手动调整它,也可以使用我的github 程序在您的机器上生成它。

# Package Information for pkg-config

prefix=/usr/local/Cellar/boost/1.60.0_2
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir_old=${prefix}/include/boost
includedir_new=${prefix}/include

Name: Boost
Description: Boost is awesome
Version: 1.60.0
Libs: -L${exec_prefix}/lib  -lboost_prg_exec_monitor-mt 
-lboost_math_c99f-mt -lboost_unit_test_framework-mt 
-lboost_container-mt -lboost_log_setup -lboost_math_tr1l 
-lboost_graph-mt -lboost_wserialization-mt -lboost_log-mt 
-lboost_math_c99f -lboost_type_erasure -lboost_signals-mt 
-lboost_test_exec_monitor -lboost_filesystem -lboost_thread-mt 
-lboost_math_tr1f-mt -lboost_date_time -lboost_timer 
-lboost_math_tr1f -lboost_test_exec_monitor-mt -lboost_container 
-lboost_math_tr1 -lboost_type_erasure-mt 
-lboost_program_options-mt -lboost_graph -lboost_log_setup-mt 
-lboost_random -lboost_system -lboost_system-mt -lboost_locale-mt 
-lboost_wserialization -lboost_regex -lboost_exception 
-lboost_timer-mt -lboost_signals -lboost_filesystem-mt 
-lboost_math_c99-mt -lboost_math_tr1-mt -lboost_serialization-mt 
-lboost_serialization -lboost_prg_exec_monitor -lboost_exception-mt 
-lboost_coroutine -lboost_math_c99 -lboost_iostreams-mt 
-lboost_random-mt -lboost_program_options -lboost_atomic-mt 
-lboost_date_time-mt -lboost_math_c99l -lboost_math_tr1l-mt 
-lboost_context-mt -lboost_regex-mt -lboost_coroutine-mt 
-lboost_log -lboost_chrono-mt -lboost_wave-mt 
-lboost_iostreams -lboost_chrono -lboost_unit_test_framework 
-lboost_math_c99l-mt
Cflags: -I${includedir_old} -I${includedir_new}