升压程序选项不适用于GLIBCXX_DEBUG [英] Boost Program Options won't work with GLIBCXX_DEBUG
问题描述
我有以下示例代码:
#include< iostream>
#include< boost / program_options.hpp>
int main(int ac,char * av []){
//声明支持的选项。
boost :: program_options :: options_description desc(允许的选项);
desc.add_options()(help,产生帮助信息);
boost :: program_options :: variables_map vm;
boost :: program_options :: store(boost :: program_options :: parse_command_line(ac,av,desc),vm);
返回0;
}
g ++ test.cpp -lboost_program_options
。
但是,如果我尝试激活GCC边界检查并调用 g ++ test.cpp -lboost_program_options -D_GLIBCXX_DEBUG
,则会引发以下链接器错误:
test.cpp :( .text._ZN5boost15program_options25basic_command_line_parserIECEC2EiPKPKc [_ZN5boost15program_options25basic_command_line_parserIcEC5EiPKPKc] + 0x97):未定义的引用`boost :: program_options :: detail :: cmdline :: cmdline(std :: __ debug :: vector< std :: string,std :: allocator< std :: string>> const&)'
collect2:error:ld返回1退出状态
据我了解,链接器找不到函数 boost :: program_options :: detail :: cmdline :: cmdline(std :: __ debug: :vector< std :: string,std :: allocator< std :: string>> const&)
,因为它的参数被替换通过调试向量而不是普通的 std :: vector
。但为什么会发生?有没有人知道一种解决方法,使Boost程序选项与 GLIBCXX_DEBUG
?
一起工作我使用以下系统:
- Debian Wheezy
- g ++(Debian 4.7.2-5)4.7.2 >
- libboost-all-dev 1.49.0.1,通过aptitude安装
感谢您的帮助
错误消息在这里非常明确,链接器找不到符号
boost :: program_options :: detail :: cmdline :: cmdline(std :: __ debug :: vector< std :: string,std :: allocator< std :: string>> const& amp ;)
请注意额外的 __ debug
命名空间,这意味着您正在构建 _GLIBCXX_DEBUG
。这是行不通的,因为你的包维护者没有用这个定义构建boost库,因此链接器错误。您有几个选项:
- 删除
_GLIBCXX_DEBUG
从任何翻译单元包含程序选项头。这可能需要进行一些重构,具体取决于启用迭代器调试时要解决的问题。 - 用
-D_GLIBCCX_DEBUG
构建boost库。 。这也可能不是微不足道的,虽然boost构建系统非常简单。
I have the following sample code:
#include <iostream>
#include <boost/program_options.hpp>
int main ( int ac, char *av[] ) {
// Declare the supported options.
boost::program_options::options_description desc("Allowed options");
desc.add_options()("help", "produce help message");
boost::program_options::variables_map vm;
boost::program_options::store(boost::program_options::parse_command_line(ac, av, desc), vm);
return 0;
}
It compiles fine using e.g. g++ test.cpp -lboost_program_options
.
However if I try to activate GCC bounds checking with the call g++ test.cpp -lboost_program_options -D_GLIBCXX_DEBUG
, it throws the following linker error:
/tmp/ccZLdZ1g.o: In function `boost::program_options::basic_command_line_parser<char>::basic_command_line_parser(int, char const* const*)':
test.cpp:(.text._ZN5boost15program_options25basic_command_line_parserIcEC2EiPKPKc[_ZN5boost15program_options25basic_command_line_parserIcEC5EiPKPKc]+0x97): undefined reference to `boost::program_options::detail::cmdline::cmdline(std::__debug::vector<std::string, std::allocator<std::string> > const&)'
collect2: error: ld returned 1 exit status
As far as I understand the linker can't find the function boost::program_options::detail::cmdline::cmdline(std::__debug::vector<std::string, std::allocator<std::string> > const&)
, because its argument is replaced by a debug vector instead of normal std::vector
. But why does this happen? And does anyone know a workaround, to make Boost Program Options work with GLIBCXX_DEBUG
?
I use the following system:
- Debian Wheezy
- g++ (Debian 4.7.2-5) 4.7.2
- libboost-all-dev 1.49.0.1, installed via aptitude
Thanks for any help
The error message is very clear here, the linker cannot find the symbol
boost::program_options::detail::cmdline::cmdline(std::__debug::vector<std::string, std::allocator<std::string> > const&)
note the additional __debug
namespace, which implies you are building with _GLIBCXX_DEBUG
. This won't work since your package maintainer did not build the boost libraries with this defined, hence the linker error. You have a few options
- remove
_GLIBCXX_DEBUG
from whatever translation units include the program options headers. This might require some refactoring depending on what you're trying to solve with iterator debugging enabled. - build the boost libraries with
-D_GLIBCCX_DEBUG
. This also may not be trivial, though the boost build system is fairly straightforward.
这篇关于升压程序选项不适用于GLIBCXX_DEBUG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!