Warning: Creating default object from empty value in /home/mirandam/public_html/linux/wp-includes/functions.php on line 292
Fedora, Linux and Stuff :: Using Alternate Compilers

Using Alternate Compilers

Tuesday, November 15th, 2005 ~ 10:49 pm by Mauriat Miranda

Users of Fedora Core 4, SuSE 10.0 and other distributions with GCC v4 may have found some open source softwares may not compile properly. Using alternate compilers may resolve the problem. FC4 also ships with GCC v3.2. There are many ways to specify alternate compilers during the build process, below are some ways.

Environment Variables
Most softwares support the CC and CXX environment variables. First assign them, then run configure or make. Example:

# export CC=gcc32
# export CXX=g++32
# ./configure

A good example can be found on the Redhat Mailing List.

Configure Support
If the software is using the standard GNU automake and configure, then there is a chance it supports other compilers by passing in a setting to the configure script. First run configure --help to see if it mentions anything. The following example is from MPlayer:

# ./configure --help
# ./configure --cc=gcc32

Makefile Support
Sometimes the software may just come with a Makefile. Open the Makefile and look inside to see if there are variables that specify the compiler. You can either edit those variables or set them at compile time. For example:

(in Makefile)
	
C_COMPILER = cc
CPLUSPLUS_COMPILER = c++

Then using the makefile, you can run:

# make CPLUSPLUS_COMPILER=g++32

Although the above examples are not exhaustive they should provide some ideas for using alternate compilers in Fedora Core and other Linux distributions.

I am also providing some notes from my FC4 Guide on GCC and GCC Compatability Libraries.

9 Responses to “Using Alternate Compilers”

  1. Aaron Says:

    # export CC=gcc32
    # export CPP=g++32
    # ./configure

    Please note, it only worked for me when I used CXX (C++ compiler) instead of CPP (pre-processor).

  2. Mauriat Says:

    Aaron: You are correct. Thanks

  3. Chris Says:

    Finally, FINALLY someone explains this. I have had a migraine since 4.x was released. In most cases this works. “Some” is an understatement when it comes to software that does not compile on Suse 10 or Fedora 4 if you ask me, its about 95%. Thanks for Posting this I am very greatful for the information!!!

  4. Dinh Says:

    I have a gcc4.0 on my Mandriva and I need to run programs with gcc3.4.3. I installed gcc3.4.3 but then I dont know how to change gcc3.4.3 as default compiler? Any help please?

    In the discussion below, did u mean: If I use “make c++=g++34″, my program will be compiled with gcc3.4?

    Thanks

  5. Mauriat Says:

    Dinh:
    How did you install gcc3.4.3? (Did you install yourself? Or did you use a supported RPM?)
    What program are you trying to compile?

    You can only run ‘make c++=g++34′ if the ‘Makefile’ you are using supports the variable ‘c++’. Open ‘Makefile’ and look for that variable.

  6. Awais Says:

    Changing Default GCC
    I have to change the gcc version from the default 3.x or 4.x to gcc2.95 as I am working in NS which does not even comple with gcc3.x.
    What I do is install the gcc2.95 in /opt and change the system variables for path etc in /etc/bashrc to include the /opt before /usr/bin/blah_blah
    Furthermore the gcc2.95 doesnt compile with gcc4.x so I have to first compile it with gcc3.x and then use it to install the version of NS I usually work on.

    For further inquiries or details you can contact me at awais(dot)lodhi(at)gmail(dot)com

  7. Krolyn Says:

    Hi all,

    I’ve had a similar problem. I needed to compile a program with gcc-3.2.3 and so installed compat-gcc-32. the compiler works perfectly (must use gcc32 instead og gcc) but I have no java support since gcj is only installed in the 4.1 version. Any idea how to use gcj with gcc-3.2.3??

    thans in adv

  8. Moritz Barsnick Says:

    All autoconf based packages support
    PROMPT> CC=mycompiler CXX=myothercompiler ./configure
    These variables therefore also work with rpmbuild (if exported).

    Most regular Makefiles also support CC/CXX make variables (note: not environment variables). But there’s no default rpmbuild method to pass them in, without modifying at least the SPEC file. Therefore, IMHO, there should be a requirement for SPEC files to properly evaluate CC/CXX.

    E.g. (not-autoconf based):
    Modify the SPEC file line
    make
    to read
    make CC=${CC:-gcc} CXX=${CXX:-g++}

    I have stumbled across this tens of times while trying to (re)build with the Intel C++ Compiler (with programs called “icc” and “icpc”). (Autoconf-based packages are fine, as I’d like to stress again, and these make up some 90% or so of the distribution, I guess.)

    Is it fair to submit bugzilla bugs against these SPEC files? Could there be a common understanding (especially among the build system folks) that this is a necessity?

    Thanks,
    Moritz

  9. Prabhu Says:

    Hi,
    Could you please tell me how do we disable auto configuration ( stateless
    FE80::) address in linux. Do we have any command or need to change any of config file in linux.

    Thanks,
    Prabhu