[LLVMdev] Building llvm from source with clang instead of gcc

Óscar Fuentes ofv at wanadoo.es
Sun Jan 6 10:36:03 PST 2013


Edward Diener <eldlistmailingz at tropicsoft.com> writes:

>> Clang will attempt to use your installed system libraries, usually
>> libstdc++ and glibc on a Linux distribution.  We could probably maintain
>> a libstdc++ compatibility table that says clang x.y is compatible with
>> libstdc++ up to z.w.  In the vast majority of cases, this just works if
>> you install a somewhat-newer version of clang.  The problems arise when
>> you use an older clang with a newer libstdc++ (e.g. newer gcc and/or
>> linux distribution).
>
> This is what evidently happens. A clang binary distribution gets
> created for a particular Linux distro but there is no compatibility in
> the package which states that it only works with some version of
> libstdc++ or glibc or earlier. Then a later version of gcc gets
> installed and with it a later version of libstdc++ and glibc as a
> dependency. Now the binary version of clang no longer works on that
> system because of the updates to the C/C++ standard library.

Then, the package system of your Linux distribution is broken. Or the
package containing the Clang binaries does not correctly state its
dependencies.

[snip]

>> Generally, it is recommended to bootstrap clang:
>>
>> 1. Build llvm/clang with system gcc
>> 2. Build llvm/clang with new clang
>> 3. Install new clang somewhere (which will automatically use system
>> libstdc++/glibc).
>>
>> This should solve your problem.

[I think Justin's recipe is overkill, but whatever]

> OK, this sounds good. Can this process not be explained on the clang
> Getting Started page for those who are building clang from source. I
> am not sure how step 3) is supposed to go. Do I just copy the built
> bin directory somewhere else and then put it first in my PATH, before
> running llvm/configure ?

You can install on a temporary directory or directly use the newly
created clang binaries, setting the environment variables CC and CXX
with full paths like this:

CC=/path/to/clang CXX=/path/to/clang++ configure [configure options] && make

Changing the PATH should work, but remeber to undo the change
afterwards.

> Or is "Install new clang" more complicated than that ?

It is simply `sudo make install' (which installs on system-level default
directories.) You can also install on a custom directory, using the
parameter `--prefix=' in the `configure' invocation.

> Originally I thought I could have both an earlier binary version of
> clang as well as the latest built version of clang in a Linux distro
> so that I could test code on both for compatibility of my library for
> end-users. But with the fairly common breakage of the binary version
> package of clang when libstdc++/glibc gets updated, this has become
> much less of a reality.

See above. You can have as much Clang versions as you please. Just be
sure to not uninstall the required gcc version for each Clang version.




More information about the llvm-dev mailing list