在使用Clang进行编译时,链接器无法在64位Mint OS下找到32位库

时间:2015-01-19 18:59:47

标签: c++ linux gcc clang mint

我刚刚在64位Mint OS(版本17)上安装了Clang 3.5。我试图用32位编译我的程序,但是我遇到了问题。

我的主目录中有一个名为test.cpp的文件,其中包含以下代码:

#include <iostream>

int main()
{
    std::cout << "Hello" << std::endl;
}

然后我运行以下命令:

$ clang++ -m32 -Wl,--verbose test.cpp | grep libgcc

我得到以下输出:

$ clang++ -m32 -Wl,--verbose test.cpp | grep libgcc
/usr/bin/ld: skipping incompatible /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/libstdc++.so when searching for -lstdc++
/usr/bin/ld: skipping incompatible /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/libstdc++.a when searching for -lstdc++
/usr/bin/ld: cannot find -lstdc++
/usr/bin/ld: skipping incompatible /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/libgcc_s.so when searching for -lgcc_s
attempt to open /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/libgcc_s.so succeeded
/usr/bin/ld: cannot find -lgcc_s
attempt to open /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/libgcc_s.a failed
attempt to open /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../i386-linux-gnu/libgcc_s.so failed
/usr/bin/ld: skipping incompatible /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/libgcc.a when searching for -lgcc
attempt to open /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../i386-linux-gnu/libgcc_s.a failed
attempt to open /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../lib32/libgcc_s.so failed
attempt to open /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../lib32/libgcc_s.a failed
attempt to open /usr/bin/../lib/i386-linux-gnu/libgcc_s.so failed
/usr/bin/ld: cannot find -lgcc
attempt to open /usr/bin/../lib/i386-linux-gnu/libgcc_s.a failed
attempt to open /usr/bin/../lib32/libgcc_s.so failed
attempt to open /usr/bin/../lib32/libgcc_s.a failed
attempt to open /lib/i386-linux-gnu/libgcc_s.so failed
attempt to open /lib/i386-linux-gnu/libgcc_s.a failed
attempt to open /lib/../lib32/libgcc_s.so failed
attempt to open /lib/../lib32/libgcc_s.a failed
attempt to open /usr/lib/i386-linux-gnu/libgcc_s.so failed
attempt to open /usr/lib/i386-linux-gnu/libgcc_s.a failed
attempt to open /usr/lib/../lib32/libgcc_s.so failed
attempt to open /usr/lib/../lib32/libgcc_s.a failed
attempt to open /usr/lib/x86_64-linux-gnu/../../lib32/libgcc_s.so failed
attempt to open /usr/lib/x86_64-linux-gnu/../../lib32/libgcc_s.a failed
attempt to open /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../libgcc_s.so failed
attempt to open /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../libgcc_s.a failed
attempt to open /usr/bin/../lib/libgcc_s.so failed
attempt to open /usr/bin/../lib/libgcc_s.a failed
attempt to open /lib/libgcc_s.so failed
attempt to open /lib/libgcc_s.a failed
attempt to open /usr/lib/libgcc_s.so failed
attempt to open /usr/lib/libgcc_s.a failed
attempt to open /usr/i386-linux-gnu/lib32/libgcc_s.so failed
attempt to open /usr/i386-linux-gnu/lib32/libgcc_s.a failed
attempt to open /usr/x86_64-linux-gnu/lib32/libgcc_s.so failed
attempt to open /usr/x86_64-linux-gnu/lib32/libgcc_s.a failed
attempt to open //usr/local/lib/i386-linux-gnu/libgcc_s.so failed
attempt to open //usr/local/lib/i386-linux-gnu/libgcc_s.a failed
attempt to open //usr/local/lib32/libgcc_s.so failed
attempt to open //usr/local/lib32/libgcc_s.a failed
attempt to open //lib/i386-linux-gnu/libgcc_s.so failed
attempt to open //lib/i386-linux-gnu/libgcc_s.a failed
attempt to open //lib32/libgcc_s.so failed
attempt to open //lib32/libgcc_s.a failed
attempt to open //usr/lib/i386-linux-gnu/libgcc_s.so failed
attempt to open //usr/lib/i386-linux-gnu/libgcc_s.a failed
attempt to open //usr/lib32/libgcc_s.so failed
attempt to open //usr/lib32/libgcc_s.a failed
attempt to open //usr/local/lib/libgcc_s.so failed
attempt to open //usr/local/lib/libgcc_s.a failed
attempt to open //lib/libgcc_s.so failed
attempt to open //lib/libgcc_s.a failed
attempt to open //usr/lib/libgcc_s.so failed
attempt to open //usr/lib/libgcc_s.a failed
attempt to open /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/libgcc.so failed
attempt to open /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/libgcc.a succeeded
attempt to open /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../i386-linux-gnu/libgcc.so failed
attempt to open /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../i386-linux-gnu/libgcc.a failed
attempt to open /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../lib32/libgcc.so failed
attempt to open /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../lib32/libgcc.a failed
attempt to open /usr/bin/../lib/i386-linux-gnu/libgcc.so failed
attempt to open /usr/bin/../lib/i386-linux-gnu/libgcc.a failed
attempt to open /usr/bin/../lib32/libgcc.so failed
attempt to open /usr/bin/../lib32/libgcc.a failed
attempt to open /lib/i386-linux-gnu/libgcc.so failed
attempt to open /lib/i386-linux-gnu/libgcc.a failed
attempt to open /lib/../lib32/libgcc.so failed
attempt to open /lib/../lib32/libgcc.a failed
attempt to open /usr/lib/i386-linux-gnu/libgcc.so failed
attempt to open /usr/lib/i386-linux-gnu/libgcc.a failed
attempt to open /usr/lib/../lib32/libgcc.so failed
attempt to open /usr/lib/../lib32/libgcc.a failed
attempt to open /usr/lib/x86_64-linux-gnu/../../lib32/libgcc.so failed
attempt to open /usr/lib/x86_64-linux-gnu/../../lib32/libgcc.a failed
attempt to open /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../libgcc.so failed
attempt to open /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../libgcc.a failed
attempt to open /usr/bin/../lib/libgcc.so failed
attempt to open /usr/bin/../lib/libgcc.a failed
attempt to open /lib/libgcc.so failed
attempt to open /lib/libgcc.a failed
attempt to open /usr/lib/libgcc.so failed
attempt to open /usr/lib/libgcc.a failed
attempt to open /usr/i386-linux-gnu/lib32/libgcc.so failed
attempt to open /usr/i386-linux-gnu/lib32/libgcc.a failed
attempt to open /usr/x86_64-linux-gnu/lib32/libgcc.so failed
attempt to open /usr/x86_64-linux-gnu/lib32/libgcc.a failed
attempt to open //usr/local/lib/i386-linux-gnu/libgcc.so failed
attempt to open //usr/local/lib/i386-linux-gnu/libgcc.a failed
attempt to open //usr/local/lib32/libgcc.so failed
attempt to open //usr/local/lib32/libgcc.a failed
attempt to open //lib/i386-linux-gnu/libgcc.so failed
attempt to open //lib/i386-linux-gnu/libgcc.a failed
attempt to open //lib32/libgcc.so failed
attempt to open //lib32/libgcc.a failed
attempt to open //usr/lib/i386-linux-gnu/libgcc.so failed
attempt to open //usr/lib/i386-linux-gnu/libgcc.a failed
attempt to open //usr/lib32/libgcc.so failed
attempt to open //usr/lib32/libgcc.a failed
attempt to open //usr/local/lib/libgcc.so failed
attempt to open //usr/local/lib/libgcc.a failed
attempt to open //lib/libgcc.so failed
attempt to open //lib/libgcc.a failed
attempt to open //usr/lib/libgcc.so failed
attempt to open //usr/lib/libgcc.a failed
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我已经完成了所有谷歌搜索和自我调查,我可以,我不确定为什么这个简单的例子不起作用。任何人都可以帮助弄清楚我错过了什么吗?

2 个答案:

答案 0 :(得分:6)

以下是使用clang进行交叉编译时要确定的内容:

  • 您安装了32位(x86)C ++库吗? (看来你有,但只是确定。)

  • 尝试使用--sysroot=<location of your 32-bit multilibs>。这将告诉clang在您告诉它的特定目录中搜​​索binlibinclude目录,而不是使用其(定义不明确的)硬编码路径。

  • 尝试使用-I-L选项更具体地告诉clang你的include和lib目录的位置。

  • 如果上述方法都不奏效,最糟糕的情况是:尝试使用-B <path>选项告诉clang具体使用哪个链接器。尝试将此项与之前的选项结合使用。

有关详细信息,请参阅http://clang.llvm.org/docs/CrossCompilation.html(尽管此处未涵盖-B选项)

答案 1 :(得分:3)

您需要安装multilib g ++ sudo apt-get install g++-multilib

g++-multilib还应安装所有其他必需的依赖项,例如libc6-i386