如何构建 Boost::program_options(在 Linux 上)
我正在尝试按照官方说明使用 boost::program_options
: http://www.boost.org/doc/libs/1_36_0/more/getting_started/unix-variants.html#link -your-program-to-a-boost-library
但它不起作用:
~/download/boost_1_36_0/libs/program_options/example> g++ -o first first.cpp /usr/lib64/libboost_program_options-mt-1_36.a /tmp/ccNh69JH.o: In function `main': first.cpp:(.text+0xc8): undefined reference to `boost::program_options::options_description::options_description(std::basic_string, std::allocator > const&, unsigned int, unsigned int)' /tmp/ccNh69JH.o: In function `std::basic_string, std::allocator > const& boost::program_options::validators::get_single_string(std::vector, std::allocator >, std::allocator, std::allocator > > > const&, bool)': first.cpp:(.text._ZN5boost15program_options10validators17get_single_stringIcEERKSbIT_St11char_traitsIS3_ESaIS3_EERKSt6vectorIS7_SaIS7_EEb[std::basic_string, std::allocator > const& boost::program_options::validators::get_single_string(std::vector, std::allocator >, std::allocator, std::allocator > > > const&, bool)]+0x142): undefined reference to `boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t, std::basic_string, std::allocator > const&, std::basic_string, std::allocator > const&)' first.cpp:(.text._ZN5boost15program_options10validators17get_single_stringIcEERKSbIT_St11char_traitsIS3_ESaIS3_EERKSt6vectorIS7_SaIS7_EEb[std::basic_string, std::allocator > const& boost::program_options::validators::get_single_string(std::vector, std::allocator >, std::allocator, std::allocator > > > const&, bool)]+0x2e9): undefined reference to `boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t, std::basic_string, std::allocator > const&, std::basic_string, std::allocator > const&)' collect2: ld returned 1 exit status
这有效,但很奇怪:
g++ -o first first.cpp /usr/lib64/libboost_program_options.so.1.42.0
I'm trying to use boost::program_options
following the official instruction: http://www.boost.org/doc/libs/1_36_0/more/getting_started/unix-variants.html#link-your-program-to-a-boost-library
But it doesn't work:
~/download/boost_1_36_0/libs/program_options/example> g++ -o first first.cpp /usr/lib64/libboost_program_options-mt-1_36.a /tmp/ccNh69JH.o: In function `main': first.cpp:(.text+0xc8): undefined reference to `boost::program_options::options_description::options_description(std::basic_string, std::allocator > const&, unsigned int, unsigned int)' /tmp/ccNh69JH.o: In function `std::basic_string, std::allocator > const& boost::program_options::validators::get_single_string(std::vector, std::allocator >, std::allocator, std::allocator > > > const&, bool)': first.cpp:(.text._ZN5boost15program_options10validators17get_single_stringIcEERKSbIT_St11char_traitsIS3_ESaIS3_EERKSt6vectorIS7_SaIS7_EEb[std::basic_string, std::allocator > const& boost::program_options::validators::get_single_string(std::vector, std::allocator >, std::allocator, std::allocator > > > const&, bool)]+0x142): undefined reference to `boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t, std::basic_string, std::allocator > const&, std::basic_string, std::allocator > const&)' first.cpp:(.text._ZN5boost15program_options10validators17get_single_stringIcEERKSbIT_St11char_traitsIS3_ESaIS3_EERKSt6vectorIS7_SaIS7_EEb[std::basic_string, std::allocator > const& boost::program_options::validators::get_single_string(std::vector, std::allocator >, std::allocator, std::allocator > > > const&, bool)]+0x2e9): undefined reference to `boost::program_options::validation_error::validation_error(boost::program_options::validation_error::kind_t, std::basic_string, std::allocator > const&, std::basic_string, std::allocator > const&)' collect2: ld returned 1 exit status
This works but it is weird:
g++ -o first first.cpp /usr/lib64/libboost_program_options.so.1.42.0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您已包含标头、编译了库并正确添加了对它们的引用,我可以建议您一种快速(且懒惰)的方法来解决问题。您可以将源文件添加到项目中,并在制定解决方案时将它们一起编译
Assuming you've included the header, compiled the libraries and added a reference to them correctly, I can suggest you a fast (and lazy) way to solve the problem. You can add the source files to the project and compile them together while you work the solution out
我创建了一个包含以下内容的 boost.pc 文件:
现在我可以运行类似的东西
(通过 makefile)
I've created a boost.pc file with following contents:
Now I can run something like
(via makefile)