Compile C++ program with devtoolset for 32 bits

Issues related to applications and software problems
Post Reply
dtrosset
Posts: 1
Joined: 2017/09/06 13:08:54

Compile C++ program with devtoolset for 32 bits

Post by dtrosset » 2017/09/06 13:24:51

I want to compile my C++ program for a 32 bits CentOS-6 system.
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
$
Why does the linker want the non shared version of the standard C++ library? Why can't it use the default one (libstdc++-i686 is already installed)
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?

Whoever
Posts: 1033
Joined: 2013/09/06 03:12:10

Re: Compile C++ program with devtoolset for 32 bits

Post by Whoever » 2017/09/06 15:15:21

Perhaps try an older version of devtoolset?

devtoolset-2 provides the 32-bit libraries. Perhaps you can find a version of devtoolset that provides both 32-bit libraries and the c++ features you need.

chemal
Posts: 427
Joined: 2013/12/08 19:44:49

Re: Compile C++ program with devtoolset for 32 bits

Post by chemal » 2017/09/06 22:14:07

Why does the linker want the non shared version of the standard C++ library? Why can't it use the default one (libstdc++-i686 is already installed)
Because the system's copy of libstdc++ is from gcc 4.4.7. Everything added after gcc 4.4.7 up to gcc 6.3.1 is missing. All the new stuff is in /opt/rh/devtoolset-6/root/usr/lib/gcc/i686-redhat-linux/6.3.1/libstdc++_nonshared.a. This would be package devtoolset-6-libstdc++-devel-6.3.1-3.1.el6.i686.rpm, but RH doesn't supply it. You can get it here:

https://copr-be.cloud.fedoraproject.org ... set-6-gcc/

Post Reply