在 Boost 库 (program_options) 中编译失败

Compilation fail in Boost librairies (program_options)

本文关键字:编译 失败 options Boost program      更新时间:2023-10-16

今天我重建了我的C++应用程序,编译失败了。不过,一切都没有改变。第一个错误是在我的类List中,它继承自这里的std::vector(私有继承):

template<typename T> void List<T>::append(const T& value)
{
    push_back(value);
}

我必须在push_back(value);之前添加std::vector<T>::,因为编译器找不到任何声明。我真的不知道为什么会这样,但是有一个 g++ 的更新,我现在使用 g++ v4.7.0(预发行版)在 Arch Linux 上使用 C++11。

我解决了这个问题,但现在真正的问题是,由于 Boost 库program_options中的问题,我无法编译应用程序的其余部分。我将库与以下内容包括在内:

#include <boost/config.hpp>
#include <boost/program_options/detail/config_file.hpp>
#include <boost/program_options/parsers.hpp>

错误:

g++ -m64 -pipe -pedantic -Wextra -std=gnu++0x   -c -g -Wall -DDEBUG -DDEV -DMYSQL_SUPPORT -I. -IHeaders -MMD -MP -MF build/Debug/GNU-Linux-x86/Sources/Libs/Settings.o.d -o build/Debug/GNU-Linux-x86/Sources/Libs/Settings.o Sources/Libs/Settings.cpp
/usr/include/boost/program_options/detail/config_file.hpp: In instantiation of ‘bool boost::program_options::detail::basic_config_file_iterator<charT>::getline(std::string&) [with charT = char; std::string = std::basic_string<char>]’:
In file included from Sources/Libs/Settings.cpp:33:0:
Sources/Libs/Settings.cpp:69:24:   required from here
/usr/include/boost/program_options/detail/config_file.hpp:163:13: erreur: ‘to_internal’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
In file included from /usr/include/boost/program_options/detail/parsers.hpp:9:0,
                 from /usr/include/boost/program_options/parsers.hpp:265,
                 from Sources/Libs/Settings.cpp:34:
/usr/include/boost/program_options/detail/convert.hpp:75:34: note: ‘template<class T> std::vector<std::basic_string<char> > boost::program_options::to_internal(const std::vector<T>&)’ declared here, later in the translation unit

我的 List 类相同的错误...

谢谢!

我怀疑您已经被 gcc 4.7 中模板实例化的两阶段查找规则的变化所困扰。

如果没有源代码,我无法给出更实用的建议,但是 gcc4.7 更改(第 C++ 章)给出了两阶段查找的描述,并提出了一些代码更正建议。