与Clang编译时,链接程序无法在64位Mint OS下find32位库

我刚刚在64位Mint操作系统(版本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) 

我已经完成了所有的search和自我调查,我可以,我不知道为什么这个简单的例子不工作。 任何人都可以帮助找出我失踪的东西吗?

你需要安装一个multilib g ++ sudo apt-get install g++-multilib

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

与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选项不包含在那里)