Clang problem with 32-bit builds on OS Leap 42.2

The clang distributed with OS Leap 42.2 is somehow not setup correctly for 32-bit builds. I can compile successfully with the -m32 switch but once I attempt to link my 32-bit object files with clang it fails because it is looking for gcc 64-bit startup files and libraries. Is there a workaround for this or some package I need to install which will get clang to work correctly. Using gcc for 32-bit or 64-bit builds there is no problem, and using clang for 64-bit builds there is no problem.

Although you can specify the specific gcc needed in your build script,
As an alternative you can also set up an “update alternatives” to switch between gcc as I describe here

https://en.opensuse.org/User:Tsu2/gcc_update-alternatives

TSU

Try “clang -target i386”.

The gcc compiler works fine, nor does this have anything to do with the version of gcc being used when I invoke gcc ( or g++ ). I can invoke whatever version of gcc I want since they all have different executables with different names. Furthermore passing -m32 for a 32-bit build or -m64 for a 64-bit build works fine when using gcc, both during the compile and link stages.

Using clang as distributed by OS Leap 42.2 also works fine when passing -m64 for a 64-bit build, both during the compile and link stages. It is when invoking clang for 32-bit builds, using the -m32 switch, where clang fails to link because it is looking to use the gcc 64-bit startup files and libraries instead of the corresponding gcc 32-bit startup files and libraries. Remember that clang uses gcc as its back end, and in particular uses the gcc linker after compilation to link object files it creates. Why it is passing to the gcc linker, when doing 32-bit build, options which tell it to link the 64-bit startup files and use the 64-bit gcc run-time libraries I do not know. But something is wrong.

Is that a compile flag, a link flag, or both ?

When I try it as a compile flag I get the compilation error:

config_info.cpp:1:10: fatal error: ‘iostream’ file not found
#include <iostream>

When I try it without the “-target i386” the compile is successful but the linker gives me:

/usr/bin/ld: skipping incompatible /usr/bin/…/lib64/gcc/x86_64-suse-linux/6/…/…/…/libm.so when searching for -lm
/usr/bin/ld: skipping incompatible /usr/bin/…/lib64/gcc/x86_64-suse-linux/6/…/…/…/libc.so when searching for -lc
/usr/bin/ld: i386:x86-64 architecture of input file /usr/bin/../lib64/gcc/x86_64-suse-linux/6/../../../crt1.o' is incompatible with i386 output /usr/bin/ld: i386:x86-64 architecture of input file /usr/bin/…/lib64/gcc/x86_64-suse-linux/6/…/…/…/crti.o’ is incompatible with i386 output
/usr/bin/ld: i386:x86-64 architecture of input file `/usr/bin/…/lib64/gcc/x86_64-suse-linux/6/…/…/…/crtn.o’ is incompatible with i386 output
/usr/bin/ld: /usr/bin/…/lib64/gcc/x86_64-suse-linux/6/…/…/…/crt1.o: file class ELFCLASS64 incompatible with ELFCLASS32
/usr/bin/ld: final link failed: File in wrong format
clang-3.8: error: linker command failed with exit code 1 (use -v to see invocation)

It worked with “-target i386” as a link flag. Thanks ! I wonder why gcc works without that link flag while clang, under OS 42.2, requires it. Using clang under other Linux distros works properly in 32-bit builds without that link flag.