Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linker fails to find 32-bit libraries under 64-bit Mint OS when compiling with Clang

I just installed Clang 3.5 on 64-bit Mint OS (version 17). I'm trying to compile my program in 32-bit, however I'm running into problems.

I have a file called test.cpp in my home directory with the following code:

#include <iostream>

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

I then run the following command:

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

I get the following output:

$ 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)

I've done all of the Googling and self-investigation on this that I can, I'm not sure why this simple example isn't working. Can anyone help figure out what I'm missing?

like image 534
void.pointer Avatar asked Jan 09 '23 02:01

void.pointer


1 Answers

Here's what to make sure of when cross-compiling with clang:

  • Have you installed 32-bit (x86) C++ libs? (It seems that you have, but just making sure.)

  • Try using the --sysroot=<location of your 32-bit multilibs>. This will tell clang to search for the bin, lib, and include directories within the specific directory you tell it, instead of using its (poorly defined) hardcoded paths.

  • Try using the -I and -L options to tell clang even more specifically where your include and lib dirs are.

  • Worst case if none of the above work: Try using the -B <path> option to tell clang what linker to use specifically. Try adding this in combination with the previous options, as well.

See http://clang.llvm.org/docs/CrossCompilation.html for more specifics (although the -B option is not covered there)

like image 91
mauzel Avatar answered Jan 22 '23 15:01

mauzel