[cfe-dev] Generating 32-bit Code on 64-bit Linux System

Eli Friedman eli.friedman at gmail.com
Tue Sep 13 14:34:55 PDT 2011


On Tue, Sep 13, 2011 at 2:22 PM, John Criswell <criswell at illinois.edu> wrote:
> On 9/13/11 4:15 PM, Victor Bogado da Silva Lins wrote:
>>
>> John Criswell<criswell at illinois.edu>  wrote:
>>
>>> Dear All,
>>>
>>> I'm trying to compile a "Hello, world!" C++ program on a 64-bit Linux
>>> machine into a 32-bit ELF program using Clang as follows:
>>>
>>> clang++ -o test -m32 test.cpp
>>>
>>> Unfortunately, I get the following error:
>>>
>>> /usr/bin/ld: skipping incompatible
>>> /usr/lib/gcc/x86_64-redhat-linux6E/4.4.4/libstdc++_nonshared.a when
>>> searching for -lstdc++_nonshared
>>> /usr/bin/ld: cannot find -lstdc++_nonshared
>>>
>>> Am I using the correct flags to get clang++ to generate 32-bit code?
>>> If
>>> so, does anyone know what the problem might be?  Omitting the -m32
>>> generates a 64-bit executable correctly.
>>>
>>> On a related note, is there an LLVM configure option that will generate
>>>
>>> a clang executable that always generates 32-bit code?
>>>
>> You probably dont have the 32bit version of the standard lib installed
>
> I think I do:
>
> % yum list libstdc++
> ...
> Installed Packages
> libstdc++.i386                       4.1.2-50.el5
> installed
> libstdc++.x86_64                     4.1.2-50.el5
> installed
>
> Is it possible that the Clang build isn't finding this library?  Does
> anyone know how Clang finds the standard C++ library?

See lib/Driver/ToolChains.cpp in clang.  It's messy.

-Eli




More information about the cfe-dev mailing list