gpt4 book ai didi

c++ - 如何构建 Boost::program_options(在 Linux 上)

转载 作者:搜寻专家 更新时间:2023-10-31 01:58:09 26 4
gpt4 key购买 nike

我正在尝试按照官方说明使用 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

This works but it is weird:

g++ -o first first.cpp /usr/lib64/libboost_program_options.so.1.42.0

最佳答案

假设您已经包含 header 、编译库并正确添加对它们的引用,我可以建议您采用一种快速(且懒惰)的方法来解决问题。您可以将源文件添加到项目中,并在解决方案时将它们一起编译

关于c++ - 如何构建 Boost::program_options(在 Linux 上),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4536132/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com