OSDev.org

The Place to Start for Operating System Developers
It is currently Sun Apr 28, 2024 5:13 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Cross-Compiler Problem - GMP and MPFR
PostPosted: Mon Jun 02, 2008 9:18 am 
Offline
Member
Member
User avatar

Joined: Sun Oct 22, 2006 7:01 am
Posts: 2646
Location: Devon, UK
Hi,

I know there's a topic along very similar lines here at the moment, but this is kind of a new question.

I'm having a go at building the [wiki]GCC Cross-Compiler[/wiki] at the moment with Binutils 2.18 and GCC 4.3.0, but have stumbled upon the GMP and MPFR error which is becoming infamous!

I re-ran Cygwin's setup with GMP, LibGMP, MPFR and LibMPFR, but still no good. So, I have cross-compiled GMP and MPFR, which seems to be OK (they are installed, no build errors in /usr/cross/lib with headers in /usr/cross/include. By default, I still got the common error message:

Code:
checking for correct version of gmp.h... yes
checking for correct version of mpfr.h... no
configure: error: Building GCC requires GMP 4.1+ and MPFR 2.3.0+.
Try the --with-gmp and/or --with-mpfr options to specify their locations.
Copies of these libraries' source code can be found at their respective
hosting sites as well as at ftp://gcc.gnu.org/pub/gcc/infrastructure/.
See also http://gcc.gnu.org/install/prerequisites.html for additional info.
If you obtained GMP and/or MPFR from a vendor distribution package, make
sure that you have installed both the libraries and the header files.
They may be located in separate packages.


So, I tried again with the following:

Code:
Adam J@ADAMJ /usr/src/build-gcc
$ ../gcc-4.3.0/configure --target=$TARGET --prefix=$PREFIX \
--disable-nls --enable-languages=c,c++ --with-newlib \
--without-headers --with-gmp=$PREFIX --with-mpfr=$PREFIX


But still get the same error message. As per the GNU web page, I have also tried using --with-gmp-lib=... and --with-gmp-include=... and the same parameters for mpfr.

Any ideas what I should be doing differently? I seem to have working library paths which I am pointing GCC to in exactly the way stated on the GNU site.

Cheers,
Adam


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 10:06 am 
Offline
Member
Member
User avatar

Joined: Tue Jul 10, 2007 5:27 am
Posts: 2935
Location: York, United Kingdom
Hi,

Have you ensured that you compiled GMP before you compiled MPFR? MPFR relies on GMP, so if you compiled that first then it will be based off the cygwin standard GMP, which could be why configure is failing.

Cheers,

James

_________________
Horizon - a framework and language for SAS-OS development
Project 'Pedigree'
Practical x86 OSDev tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 10:16 am 
Offline
Member
Member

Joined: Mon Apr 09, 2007 12:10 pm
Posts: 775
Location: London, UK
Generally as part of its tests, configure will try and compile something with said libraries. If you examine the config.log file you might be able to track down the command line it tried to execute which failed and see the output from the compiler at the failure. Search it for gmp or something.

edit: alternatively...

Regards,
John.

_________________
Tysos | rpi-boot


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 10:25 am 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 9:29 pm
Posts: 2426
Location: Canada
I can confirm that binutils-2.18 and gcc-4.3.0 work on OpenBSD 4.3 without problems, using the instructions on the Wiki(Minus --with-newlib on GCC):
Code:
[os-cross]~: $ i686-elf-gcc -v       
Using built-in specs.
Target: i686-elf
Configured with: ../gcc-4.3.0/configure --target=i686-elf --prefix=/home/os-cross --disable-nls --enable-languages=c --without-headers --with-gmp=/usr/local --with-mpfr=/usr/local
Thread model: single
gcc version 4.3.0 (GCC)
[os-cross]~: $ i686-elf-as -v 
GNU assembler version 2.18 (i686-elf) using BFD version (GNU Binutils) 2.18
[os-cross]~: $
@AJ, You need to ensure --with-gmp/mpfr point the locations of the "installed" libraries, in my case, gmp-4.2.2 and 2.3.1 are in /usr/local (Adhering the proper hier, libraries in /usr/local/lib, headers in /usr/local/include..)

I'll never understand why people have problems following instructions... every time I try to repeat them.. it's successful. :roll:

_________________
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 10:31 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 decided to put a [no] in the tested table for now as it does not work obviously. For the moment that should deter beginners from using it.

That said, from what I figured about GMP and MPFR is that they optimize out transcendent functions - a feature not present in prior versions, and one which we probably won't use for average compile work either. jnc100's link suggested that GCC could be compiled without them, so figuring that out would provide us with a 4.3.0 GCC with all the upgrades but without that bulky feature we're not going to use anyway.

That said, the GCC devs could IMO have done that a bit better. :(

edit: @Brynet-Inc: we're talking cygwin here.

_________________
"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 ]


Last edited by Combuster on Mon Jun 02, 2008 10:32 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 10:31 am 
Offline
Member
Member
User avatar

Joined: Sun Oct 22, 2006 7:01 am
Posts: 2646
Location: Devon, UK
Thanks for the tips guys - I don't have my development machine again until tomorrow but will give it a go with the suggestions then.

Also, although I build GMP first as JamesM suggested, I didn't point MPFR to my new GMP installation - d'oh!

Cheers,
Adam

Edit (@Combuster): I have placed a scratchpad wiki page under my user name so that I can track my progress with this one. Once I have got it compiling nicely a few times, I'll format and word it all properly and add it to the main wiki (unless someone else gets there first).


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 10:35 am 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 9:29 pm
Posts: 2426
Location: Canada
Why should it be marked as "No" when it does actually work? The problem is Cygwin/user related.. :roll:

Anyway, Binary constants look like a neat new feature in GCC 4.3.0. :)

_________________
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 02, 2008 10:56 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
Brynet-Inc wrote:
Why should it be marked as "No" when it does actually work? The problem is Cygwin/user related.. :roll:

Hence, like you said, it is known to *not* work. It takes only one counterexample to disprove a statement - in this case "This works for the combination 2.18 and 4.3.0" is wrong, because it does not hold under all circumstances (i.e. cygwin).

_________________
"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:
PostPosted: Mon Jun 02, 2008 3:54 pm 
Offline
Member
Member
User avatar

Joined: Tue Oct 17, 2006 9:29 pm
Posts: 2426
Location: Canada
@AJ, http://www.osdev.org/wiki/User:AJ/Building_GMP is wrong... --build should be omitted, and --prefix should be where your host OS keeps 3rd party packages, It's GCC that needs to be linked with those libraries not your freestanding environment.

Now, If you were porting GCC to your OS, then yes, they would be required. ;)

In my setup, I installed both gmp/mpfr via OpenBSD ports system... :)

_________________
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 03, 2008 2:04 am 
Offline
Member
Member
User avatar

Joined: Sun Oct 22, 2006 7:01 am
Posts: 2646
Location: Devon, UK
Thanks Brynet,

Obviously one of the first rules of OS Devving is 'know your toolchain' and I'm now pretty confident with GCC, having built cross-compilers and a custom toolchain, but GMP and MPFR are two tools I have never used, so I panicked and applied the same rules as for building Binutils and GCC.

I have sat back and had a look at what I am doing and am going to try again today. One thing that I find odd is that with Cygwin's default LibGMP and LibMPFR installed, it still doesn't seem to work despite the fact they seem to be the version numbers required by GCC (Cygwin's GMP is 4.2.2 and MPFR is 2.3.1).

It does look like others have had success, so I'm going to assume a broken Cygwin installation in addition to error ID10-T, and will reinstall from scratch.

Cheers,
Adam


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 03, 2008 5:05 am 
Offline
Member
Member
User avatar

Joined: Sun Oct 22, 2006 7:01 am
Posts: 2646
Location: Devon, UK
Ok, thanks again for the help everyone. I now have a working 4.3.0 cross compiler and binutils for i586.

I have written down exactly what I did at [wiki]User:AJ/Building GMP[/wiki] and would be grateful if some others could follow this on Cygwin to let me know if it goes OK for you too. If so, I will format the article properly and add a link to it somewhere in the [wiki]GCC Cross-Compiler[/wiki] article. If I get enough positive responses, I can update that grid to 'yes' as well ;)

Apologies to Brynet if you felt I did not RTFM enough initially - I started out yesterday afternoon but after a good night's sleep, it all became much clearer :)

Cheers,
Adam


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 03, 2008 5:45 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7614
Location: Germany
Combuster wrote:
Brynet-Inc wrote:
Why should it be marked as "No" when it does actually work? The problem is Cygwin/user related.. :roll:

Hence, like you said, it is known to *not* work. It takes only one counterexample to disprove a statement - in this case "This works for the combination 2.18 and 4.3.0" is wrong, because it does not hold under all circumstances (i.e. cygwin).


The fine point being that, at least initially, the how-to in the Wiki was primarily written for Cygwin... 8)

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 03, 2008 11:36 am 
Offline
Member
Member

Joined: Mon Apr 09, 2007 12:10 pm
Posts: 775
Location: London, UK
I think AJs article should include some reason behind the new dependencies on gmp and mpfr (I don't like to edit an article in someone else's namespace). Someone please correct me if I'm wrong:

As far as I understand, gmp and mpfr are used to help gcc perform optimisations. The general idea is that if the compiler can determine that a value is loaded to a variable, and then an operation (e.g. add, sub, mul, div etc) is performed on that variable then in fact you could just load the result to that variable and save yourself the extra instructions. The problem is that (especially with cross compilers) there is no easy way to work out on the build machine what value the target machine would actually generate as a result for the particular operation (e.g. differences with bit-lengths, rounding, epsilon values etc). These libraries provide functions that should generate the correct result on a particular target architecture, regardless of the processor the library itself is actually running on.

Regards,
John.

_________________
Tysos | rpi-boot


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 04, 2008 4:31 am 
Offline
Member
Member
User avatar

Joined: Sun Oct 22, 2006 7:01 am
Posts: 2646
Location: Devon, UK
I'll get it up on the main wiki and do some tidying up later today. I've followed the build process from scratch again and it all seems OK - perhaps someone else would like to try, though?

@jnc100: Please do add a more detailed intro - you seem to know a lot more about GCC's use of these libs than I do, so are in a better position to write it. If you want to wait until it's out of my user space and on the main wiki, I'll try to have that done later today.

Cheers,
Adam

[Edit]The page has now been moved to [wiki]Building GMP[/wiki]. When tried and tested, I will add some links to the article from relevant locations and set the 'yes' item in the main Cross-Compiler articles table.[/Edit]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 04, 2008 2:52 pm 
Offline
Member
Member

Joined: Mon Apr 09, 2007 12:10 pm
Posts: 775
Location: London, UK
AJ wrote:
Please do add a more detailed intro
Thanks, I'll try and do that when I get a chance.

To confuse things slightly: I managed to get gcc 4.3 and gmp/mpfr to cross-compile in a slightly different way. Basically, if the gmp and mpfr sources are within the gcc source directory then it will use those, so you can do something like:
Code:
cd /usr/src
tar zxf gcc-4.3.0.tar.gz
tar zxf mpfr-2.3.1.tar.gz
tar zxf gmp-4.2.2.tar.gz
cd gcc-4.3.0
ln -s ../mpfr-2.3.1 ./mpfr
ln -s ../gmp-4.2.2 ./gmp
cd ..

# the following as per cross compiler article
mkdir build-gcc
cd build-gcc
export PATH=$PATH:$PREFIX/bin
../gcc-4.3.0/configure --target=$TARGET --prefix=$PREFIX --disable-nls --enable-languages=c,c++ --without-headers --with-newlib
make all-gcc
make install-gcc
and it magically compiles gmp and mpfr and uses those instead.

Regards,
John.

_________________
Tysos | rpi-boot


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: SemrushBot [Bot] and 6 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