OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 4:11 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: GCC 4.5.0 and the cross-compiler tutorial
PostPosted: Thu May 06, 2010 12:06 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7612
Location: Germany
Transferring this from the Wiki discussion page...

GCC 4.5.0 introduces a new dependency, the MPC library, which isn't covered by the tutorial yet. But that isn't my problem.

It seems that the tutorial only works when you use /usr/local as the prefix.

During the configure step for GCC, you state --with-gmp=..., --with-mpfr=... and --with-mpc=..., which allows the build process to find the headers and linker libraries. Unfortunately the search path for the libraries does not get coded into the resulting executables:

Code:
/usr/src/build-gcc/gcc $ ldd cc1
   linux-gate.so.1 =>  (0xb804e000)
   libmpc.so.2 => not found
   libmpfr.so.1 => /usr/lib/libmpfr.so.1 (0xb7fed000)
   libgmp.so.10 => not found
   libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7fe8000)
   libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7e85000)
   libgmp.so.3 => /usr/lib/libgmp.so.3 (0xb7e3e000)
   /lib/ld-linux.so.2 (0xb804f000)


Not only does cc1 not find the libmpc.so.2 despite being told it resides in /usr/cross/lib during the configure, it also links the system-provided gmp / mpfr libraries in /usr/lib despite being told to use those in /usr/cross/lib.

I really despise this kind of autoconfig stupidity.

I don't like mixing manually-installed libraries with the code under control of my system package manager, and anyway by using $PREFIX our tutorial gives the impression of being independent of the actual location binaries are installed to - which obviously it is not.

And editing /etc/ld.so.conf isn't an option for people who are working as non-root on shared systems.

I'd really like to file this as a bug in GCC / Autoconfig, but I know what the answer would be.

How do we handle this in the tutorial? Hardcode /usr/local and scrap $PREFIX, recommend editing /etc/ld.so.conf (which would be tricky since distros differ in this regard), or something else? (Please nobody recommend setting LD_LIBRARY_PATH, that's evil.)

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: GCC 4.5.0 and the cross-compiler tutorial
PostPosted: Thu May 06, 2010 12:14 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7612
Location: Germany
Personally, I'd suggest scrapping the "installing from source" part for GMP, MPFR and MPC (which aren't cross-compile specific anyway), and instead recommend installing the appropriate packages (e.g. libmpc-devel) through the respective system package manager. That way, cross-binutils and cross-GCC can be installed anywhere you like, and you don't even have to state --with-gmp etc. during config.

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: GCC 4.5.0 and the cross-compiler tutorial
PostPosted: Thu May 06, 2010 12:24 am 
Offline
Member
Member
User avatar

Joined: Thu Dec 21, 2006 3:03 am
Posts: 1029
Location: Hobart, Australia
I totally agree with you. It seems the best solution for everybody (including, even, the people using cygwin). It's mentioned deep in the bowels of the wiki, but the only requisite package you need for Debian is 'libmpfr-dev'. It'll install everything else as a dependency.

_________________
My Personal Blog | My Software Company - Loop Foundry | My Github Page


Top
 Profile  
 
 Post subject: Re: GCC 4.5.0 and the cross-compiler tutorial
PostPosted: Thu May 06, 2010 12:28 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7612
Location: Germany
Hmmm... I just tried my own suggestion, and it doesn't work.

GCC requires mpc 0.8.0+, and e.g. my Linux Mint installs v 0.5.2...

Damn. I wouldn't want to start explaining people how to use unstable / testing repositories for their respective distros...

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: GCC 4.5.0 and the cross-compiler tutorial
PostPosted: Thu May 06, 2010 12:36 am 
Offline
Member
Member
User avatar

Joined: Thu Dec 21, 2006 3:03 am
Posts: 1029
Location: Hobart, Australia
Isn't being able to use your current operating system a prerequisite for starting off in OSDev?

_________________
My Personal Blog | My Software Company - Loop Foundry | My Github Page


Top
 Profile  
 
 Post subject: Re: GCC 4.5.0 and the cross-compiler tutorial
PostPosted: Thu May 06, 2010 1:24 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7612
Location: Germany
Yep. I should retire from the field - the reason for my libmpc being outdated is that I'm still using Mint v7.0 when v9.0 is bound for release this month. :P

So ignore my last post. Using the system package manager is the way to go.

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: GCC 4.5.0 and the cross-compiler tutorial
PostPosted: Thu May 06, 2010 2:26 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9301
Location: On the balcony, where I can actually keep 1½m distance
I'd still file the bug for the sake of it. If they do tell us "that's a feature, not a bug" we have a legit excuse to call them names.

Maybe I should try how well llvm suits as a drop-in replacement for gcc.

_________________
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]


Top
 Profile  
 
 Post subject: Re: GCC 4.5.0 and the cross-compiler tutorial
PostPosted: Thu May 06, 2010 2:54 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7612
Location: Germany
Combuster wrote:
I'd still file the bug for the sake of it.


Have fun. I got bitten by this in several projects already. It's a commen occurence in Autoconfig projects, dragging in system libraries even when being told to use different ones. It's a ***** when you want to compile for a production system using a specific version of e.g. Boost, but the Autoconfig keeps dragging in your *system* Boost, which is a completely different version...

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: GCC 4.5.0 and the cross-compiler tutorial
PostPosted: Thu May 06, 2010 9:01 am 
Offline
Member
Member

Joined: Wed Oct 18, 2006 10:43 pm
Posts: 490
Location: Kansas City, KS, USA
Solar wrote:
Personally, I'd suggest scrapping the "installing from source" part for GMP, MPFR and MPC (which aren't cross-compile specific anyway), and instead recommend installing the appropriate packages (e.g. libmpc-devel) through the respective system package manager. That way, cross-binutils and cross-GCC can be installed anywhere you like, and you don't even have to state --with-gmp etc. during config.


I'll second that. If anyone really wants to install those from source, all they have to do is unpack the GMP source to gmp/ inside the GCC source tree. Also unpack MPFR to mpfr/, and MPC to mpc/. Then GCC will compile and use the ones in the source tree instead. Supposedly anyway, I haven't tested it, but the docs say it should work.

Personally I just use my package manager to install those libraries and allow the cross compiler to link against them.


Top
 Profile  
 
 Post subject: Re: GCC 4.5.0 and the cross-compiler tutorial
PostPosted: Thu May 06, 2010 11:30 pm 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7612
Location: Germany
Putting the gmp / mpfr / mpc directories into the GCC source tree indeed works. However, the build insists on configuring libstdc++-v3, which bails out with "error: Link tests are not allowed after GCC_NO_EXECUTABLES"...

That's not only GCC 4.5.0, GCC 4.4.4 does the same.

Strange. Suddenly it's me who can't build a cross-compiler while everybody else says things are fine. #-o

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: GCC 4.5.0 and the cross-compiler tutorial
PostPosted: Thu May 06, 2010 11:39 pm 
Offline
Member
Member

Joined: Sun Jan 14, 2007 9:15 pm
Posts: 2566
Location: Sydney, Australia (I come from a land down under!)
libstdc++-v3 will only be compiled if you didn't use only "make all-gcc && make install-gcc", which the tutorial says to do.

Unless of course 4.5.0 has libstdc++-v3 included in the all-gcc target now, which would be silly.

_________________
Pedigree | GitHub | Twitter | LinkedIn


Top
 Profile  
 
 Post subject: Re: GCC 4.5.0 and the cross-compiler tutorial
PostPosted: Fri May 07, 2010 12:28 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7612
Location: Germany
/facepalm

all-gcc...

#-o

_________________
Every good solution is obvious once you've found it.


Top
 Profile  
 
 Post subject: Re: GCC 4.5.0 and the cross-compiler tutorial
PostPosted: Mon Dec 13, 2010 8:59 pm 
Offline

Joined: Mon Dec 13, 2010 8:56 pm
Posts: 5
It's a hack but to help GCC find the libraries you can create the LD_LIBRARY_PATH for example:
LD_LIBRARY_PATH=/mydir/gmp/lib:/mydir/mpc/lib:/mydir/mpfr/lib

Solar wrote:
Transferring this from the Wiki discussion page...

GCC 4.5.0 introduces a new dependency, the MPC library, which isn't covered by the tutorial yet. But that isn't my problem.

It seems that the tutorial only works when you use /usr/local as the prefix.

During the configure step for GCC, you state --with-gmp=..., --with-mpfr=... and --with-mpc=..., which allows the build process to find the headers and linker libraries. Unfortunately the search path for the libraries does not get coded into the resulting executables:

Code:
/usr/src/build-gcc/gcc $ ldd cc1
   linux-gate.so.1 =>  (0xb804e000)
   libmpc.so.2 => not found
   libmpfr.so.1 => /usr/lib/libmpfr.so.1 (0xb7fed000)
   libgmp.so.10 => not found
   libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7fe8000)
   libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7e85000)
   libgmp.so.3 => /usr/lib/libgmp.so.3 (0xb7e3e000)
   /lib/ld-linux.so.2 (0xb804f000)


Not only does cc1 not find the libmpc.so.2 despite being told it resides in /usr/cross/lib during the configure, it also links the system-provided gmp / mpfr libraries in /usr/lib despite being told to use those in /usr/cross/lib.

I really despise this kind of autoconfig stupidity.

I don't like mixing manually-installed libraries with the code under control of my system package manager, and anyway by using $PREFIX our tutorial gives the impression of being independent of the actual location binaries are installed to - which obviously it is not.

And editing /etc/ld.so.conf isn't an option for people who are working as non-root on shared systems.

I'd really like to file this as a bug in GCC / Autoconfig, but I know what the answer would be.

How do we handle this in the tutorial? Hardcode /usr/local and scrap $PREFIX, recommend editing /etc/ld.so.conf (which would be tricky since distros differ in this regard), or something else? (Please nobody recommend setting LD_LIBRARY_PATH, that's evil.)


Top
 Profile  
 
 Post subject: Re: GCC 4.5.0 and the cross-compiler tutorial
PostPosted: Mon Dec 13, 2010 9:07 pm 
Offline
Member
Member

Joined: Sun Jan 14, 2007 9:15 pm
Posts: 2566
Location: Sydney, Australia (I come from a land down under!)
Quote:
It's a hack but to help GCC find the libraries you can create the LD_LIBRARY_PATH for example

It's not a hack but to help GCC find the libraries you can use:
Code:
--with-gmp
--with-mpfr
--with-mpc


Install GMP, MPFR and MPC in one root, say, /usr, and then pass "--with-gmp=/usr" to configure and it will find the rest.

configure will probe <with_gmp_path>/lib and <with_gmp_path>/include for all three dependencies - if you have separate directories for each you'll need all three options.

There's absolutely no need to fiddle with environment variables in this tutorial, apart from adding $PREFIX/bin to $PATH (which is only necessary if you want to run the output after building it).

_________________
Pedigree | GitHub | Twitter | LinkedIn


Top
 Profile  
 
 Post subject: Re: GCC 4.5.0 and the cross-compiler tutorial
PostPosted: Mon Dec 13, 2010 10:10 pm 
Offline

Joined: Mon Dec 13, 2010 8:56 pm
Posts: 5
I had a situation where the 3 libraries were in separate places for example:

/opt/name/mpc
/opt/name/mpfr
/opt/name/gmp

and after I ran the configure using the
--with-gmp=/opt/name/gmp
--with-mpc=/opt/name/mpc
and
--with-mpfr flags=/opt/name/mpfr

the make would not complete successfully until I added the libraries to LD_LIBRARY_PATH.

I am new to this so I might have done something wrong to make the previous necessary, but it was something that I ended up having to do to successfully create a cross-compiler for a PowerPC target.

pcmattman wrote:
Quote:
It's a hack but to help GCC find the libraries you can create the LD_LIBRARY_PATH for example

It's not a hack but to help GCC find the libraries you can use:
Code:
--with-gmp
--with-mpfr
--with-mpc


Install GMP, MPFR and MPC in one root, say, /usr, and then pass "--with-gmp=/usr" to configure and it will find the rest.

configure will probe <with_gmp_path>/lib and <with_gmp_path>/include for all three dependencies - if you have separate directories for each you'll need all three options.

There's absolutely no need to fiddle with environment variables in this tutorial, apart from adding $PREFIX/bin to $PATH (which is only necessary if you want to run the output after building it).


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 19 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group