【问题标题】:G++ can't compile code using Boost for x86G++ 无法使用 Boost for x86 编译代码
【发布时间】:2012-07-08 09:09:17
【问题描述】:

我有一个问题:我使用 Boost (locks.hpp) 编写了代码。我的服务器正在运行 x64 Ubuntu (Linux)。当我用-m64 编译这段代码时,它构建得很好。但是当我尝试为-m32 编译时,我得到了这些错误:

g++ -fPIC -m32 -shared -Wl,-soname,test.so -ldl -o test.so test.cpp -lboost_thread

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../libboost_thread.so when searching for -lboost_thread
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../libboost_thread.a when searching for -lboost_thread
/usr/bin/ld: skipping incompatible //usr/lib/libboost_thread.so when searching for -lboost_thread
/usr/bin/ld: skipping incompatible //usr/lib/libboost_thread.a when searching for -lboost_thread
/usr/bin/ld: cannot find -lboost_thread
collect2: ld returned 1 exit status

我做错了什么?谢谢!

【问题讨论】:

  • 虽然我没有使用 G++ 的经验:您是否可能没有 32 位版本的 boost(有点像我如何解释“不兼容的东西”)...
  • 您确定安装了 32 位 boost 库吗?
  • @fvu 你能给我一个在 x64 ubuntu 上安装 32 位 boost 库的命令吗?
  • @Robert 不抱歉,当我读到这个askubuntu.com/questions/29665/… 时,它看起来肯定比在我使用的opensuse 上要难得多...

标签: c++ boost g++ linker-errors


【解决方案1】:

您需要 32 位版本的线程库。您的问题的answer 已经在stackoverflow.com 上。从源代码构建 boost 时使用 address-model 选项。 Boost 为在 Linux 上构建提供了出色的 documentation

bjam address-model=32

【讨论】:

  • 感谢您的回答。你能告诉我如何将这些编译的头文件和库添加到 g++ 命令中吗?
  • 您可以使用 boost "bcp" 实用程序:boost.org/doc/libs/1_50_0/tools/bcp/doc/html/index.html
  • @Dan 如果我在 64 位机器上使用 BCP 并将生成的文件夹移动到 32 位机器上,它还能工作吗?
  • @StevenRoose 是的,它会起作用的。 BCP 副本为您复制源文件和依赖项;您必须在项目中添加和构建源文件。
【解决方案2】:

尝试安装 32 位 boost 包:

sudo apt-get install libboost-thread-dev:i386 

【讨论】:

  • 不幸的是,这会强制替换当前的 64 位开发环境(编译器和许多软件包),因此它太具有侵入性。有没有办法同时拥有 32 位和 64 位?
  • @arielf,是的,有,但我不知道 Ubuntu,所以我不知道该怎么做。我很惊讶上面的命令 替换 任何东西,而不仅仅是添加一个新包。
  • 根据我的经验,这只是 boost 的一个问题。我并排安装了许多(C 语言)库(多架构:32 位和 64 位),没有任何问题。不知道为什么 boost *-dev:i386 包创建者强迫它与默认(amd64)boost -dev 包冲突。由于我已经构建/安装了几个依赖于 64 位版本的 boost 的软件包,因此他的 :i386 软件包中的 replaces 子句强制删除 1) 64 位 boost 版本和 2) 所有软件包这取决于它。 :(
  • @arielf,这不是我使用的发行版上的 Boost 包的问题,​​我会要求 Ubuntu(或 Debian)包维护者解决它
猜你喜欢
  • 2012-06-15
  • 1970-01-01
  • 2020-03-07
  • 1970-01-01
  • 2019-06-28
  • 1970-01-01
  • 1970-01-01
  • 2015-11-05
  • 2014-10-03
相关资源
最近更新 更多