My program uses C++11 features that are not available in the CentOS-6 default gcc-4.7.
Therefore I installed devtoolset-6-gcc-c++. I can compile my program for 64 bits.
Now I want to target a 32 bits CentOS-6. I compile using the -m32 flag. Link fails because of missing non shared version of standard C++ library.
Here's what I do:
Code: Select all
$ scl enable devtoolset-6 bash
$ cat hello.cpp
#include <iostream>
using std::cout;
int main()
{
cout << "Hello world!\n";
return 0;
}
$ g++ -fPIC hello.cpp -o hello
$ file hello
hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped
$ ldd hello
linux-vdso.so.1 => (0x00007ffde8f1b000)
libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007f987eaa1000)
libm.so.6 => /lib64/libm.so.6 (0x00007f987e81c000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f987e606000)
libc.so.6 => /lib64/libc.so.6 (0x00007f987e272000)
/lib64/ld-linux-x86-64.so.2 (0x00007f987edb2000)
$ ./hello
Hello world!
$ g++ -m32 -fPIC hello.cpp -o hello
/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/ld: skipping incompatible /opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/libstdc++_nonshared.a when searching for -lstdc++_nonshared
/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/ld: cannot find -lstdc++_nonshared
collect2: error: ld returned 1 exit status
$
I cannot find any libstdc++ rpm package of devtoolset-6 for 32 bits (i686)
How can I compile my C++11 program for a CentOS 32 bits system?