如何修复 boost::program_options "error: 'po' has not been declared"

如果你想使用 boost::program_options 编译你的 C++ 项目,但你看到类似这样的错误消息

build_error_output.txt
/home/uli/myProject/main.cpp:28:5: error: ‘po’ has not been declared
    po::notify (vm);

你缺少此声明,你需要将其直接放在 #include <boost/program_options.hpp> 之后:

boost_po_alias.cpp
namespace po = boost::program_options;

这将 po声明为 boost::program_options 命名空间的别名,因为写 po::variables_mapboost::program_options::variables_map 更易读,而使用 namespace boost::program_options 可能会与其他函数产生一些名称冲突。


Check out similar posts by category: Boost, C/C++