GCC questions

Peter O'Gorman peter at pogma.com
Fri Mar 21 10:15:11 PDT 2008


Alejandro Aragon wrote:
> Hello everyone,
> 
> I have several questions about using a different version of GCC than  
> that provided by default:
> 
> $ gcc -v
> Using built-in specs.
> Target: i686-apple-darwin9
> Configured with: /var/tmp/gcc/gcc-5465~16/src/configure --disable- 
> checking -enable-werror --prefix=/usr --mandir=/share/man --enable- 
> languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/ 
> $/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/ 
> lib --build=i686-apple-darwin9 --with-arch=apple --with-tune=generic -- 
> host=i686-apple-darwin9 --target=i686-apple-darwin9
> Thread model: posix
> gcc version 4.0.1 (Apple Inc. build 5465)
> 
> I built GCC43 and I have it under /opt/local/bin. I write code in C++  
> and I'm new to mac. I come from Ubuntu Linux, and it installs the  
> latest GNU compiler by default. Now the questions are:
> 
> 1. I use autotools for a project, so I can specify in the configure  
> script that the compiler be different from the default found in /usr/ 
> bin using compiler flags: $./configure CXX=/opt/include/bin/g++- 
> mp-4.3. Is there a better way to do this? I wonder what's usually  
> done. I see that g++ in /usr/bin is just a link to /usr/bin/g++-4.0.  
> If I change that link to point to the 4.3 version, I would probably  
> mess around with the system and I don't want to do that. Can anyone  
> give me suggestions on what to do here?

Setting CC/CXX as configure arguments is the way to go with configure
generated by autoconf-2.5.x (for autoconf-2.13 generated configure
scripts you should set them and export them in the environment). You do
not need to set to the full path, just, e.g. CC=gcc-mp-4.3
CXX=gcc-mp-4.3 etc. If you usually want to do that you can have a
config.site that sets them as the default if not already set. See the
autoconf manual for an example of how to do this.
<http://www.gnu.org/software/autoconf/manual/autoconf.html#Site-Defaults>


> 
> 2. Every time you #include a C++ header, I guess it looks under the / 
> usr/include directory first. Even if I specify that I want the  
> directory as a compilation flag as -I/opt/local/include/gcc43/c++/, I  
> don't think that the file under that directory will be picked instead  
> of the one installed in the system by default (/usr/include/c++/ 
> 4.0.0). I'm worried that I am using a newer gcc compiler with older  
> header files.

Header files are searched for in all the paths specified with -I before
looking in the system paths. Something like ` g++-mp-4.3 -v -x c++ -E
/dev/null' will show you the system search paths for the macports 4.3
compiler. You can add additional paths with the environment variable
CPATH - see man gcc. That said, however, the macports g++ will have set
its include search path to search for its own headers before the
systems, it is nothing to worry about.


> 
> 3. When I type echo $PATH I get
> 
> /sw/bin:/sw/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/ 
> sbin:/sbin:/usr/local/bin:/usr/texbin:/usr/X11/bin:/usr/X11R6/bin
> 
> so I guess whatever installed using macports will have priority over  
> anything else. Is there a way to accomplish the same with include paths?

Well, looks like whatever is installed by fink will have priority, then
macports, then system etc.

You really should not need to worry about setting system include paths,
the compiler will have a sane search path.

Peter
-- 
Peter O'Gorman
http://pogma.com


More information about the macports-users mailing list