c++ - 编译boost c++代码错误

标签 c++ ubuntu boost

这是代码(来自 http://www.boost.org/doc/libs/1_52_0/doc/html/container/move_emplace.html )

#include <boost/container/list.hpp>
#include <cassert>
class non_copy_movable
{
   non_copy_movable(const non_copy_movable &);
   non_copy_movable& operator=(const non_copy_movable &);

   public:
   non_copy_movable(int = 0) {}
};
int main ()
{
   using namespace boost::container;
   list<non_copy_movable> l;
   non_copy_movable ncm;
   l.emplace(l.begin(), 0);
   assert(l.size() == 1);
   l.emplace(l.begin());
   assert(l.size() == 2);
   return 0;
}

我有编译问题。我试过:

g++ 2.cpp -o 2 -I /usr/include/boost

还有其他组合,但这是错误的。

错误:

2.cpp:1:36: error: boost/container/list.hpp: No such file or directory
2.cpp: In function ‘int main()’:
2.cpp:13: error: ‘boost’ has not been declared
2.cpp:13: error: ‘container’ is not a namespace-name
2.cpp:13: error: expected namespace-name before ‘;’ token
2.cpp:14: error: ‘list’ was not declared in this scope
2.cpp:14: error: expected primary-expression before ‘>’ token
2.cpp:14: error: ‘l’ was not declared in this scope

我在路径中有“boost include”: /usr/包含/boost 在/usr/lib 中没有与 boost 相关的东西。 我已经使用以下命令在 ubuntu 上安装了 boost:

sudo apt-get install libboost-all-dev

你有boost程序的通用编译器吗? 另一个程序也是用 c++ 使用 boost 编写的,我正常编译没有错误:

g++ 1.cpp -o 1
./1

最佳答案

大多数 boost 库都是只有头文件的库,所以我并不惊讶你在/usr/lib 中看不到很多(如果有的话)boost 库。

也就是说,我认为您的包含路径设置是错误的。您正在尝试包含 boost/container/list.hpp 但您的包含路径中已经包含“boost”。除非库正在安装/usr/include/boost/boost,否则您需要从包含路径或 #include 行中删除“boost”。我的偏好是将其作为 #include <boost/container/list.hpp> 之类的语句从包含路径中删除比 #include <container/list.hpp> 信息量大得多.

关于c++ - 编译boost c++代码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14072037/

相关文章:

c++ - 是否可以 move boost::optional ?

c++ - size_t 在 C++ 中转换/转换为字符串

c++ - 使用 gSOAP 连接到 WCF Web 服务

c - 使文件/命令/可执行文件受密码保护

linux - Debian 私有(private) ppa 或替代品

c++ - 卸载boost并安装另一个版本

c++ - 将 boost async API 与多个线程一起使用

C++ - 定义类模板(头文件/源文件)

c++ - 从不兼容的指针类型分配,同时在框中添加缓冲区文本

python - 无法在 Ubuntu 16.04(64 位)上安装 Snap7 库