Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > General Coding > Coding Tutorials
You last visited: Today at 02:58

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



FreeBSD GCC-Toolchain for Linux

Discussion on FreeBSD GCC-Toolchain for Linux within the Coding Tutorials forum part of the General Coding category.

Reply
 
Old   #1

 
nico_w's Avatar
 
elite*gold: 0
Join Date: Aug 2008
Posts: 5,150
Received Thanks: 10,486
FreeBSD GCC-Toolchain for Linux

Heya,

Note: you can also adapt this tutorial for any other OS to create your own toolchain!

For my latest project, , I had to find a way to compile my stuff for FreeBSD.
My problems:
1) I wasn't able to compile my project on my server which runs FreeBSD
2) I couldn't run the bot on my server using FreeBSD's Linux emulation because it was compiled for 64bit
3) How the fuck could I build a working toolchain?

It was easier than I expected. Much easier.
After my first ~5 trys (felt like >9000), I finally got my toolchain working using GCC 4.7.3 and binutils 2.23.1.

What do we need?
- All required sources (GCC, binutils, GMP, MPFR, MPC)
- FreeBSD header files
- FreeBSD stubs
- FreeBSD libc

First, acquire all the required sources.
GCC 4.7.3:
binutils 2.23.1:
MPC 1.0.1:
MPFR 3.1.2:
GMP 5.1.1:

Create a directory in which your toolchain should reside (I used /usr/freebsd-gcc)
Move all your downloaded files into a temporary folder, I used /usr/freebsd-gcc/tmp for that.
Extract them (.tar.bz2: tar xfj ; .tar.gz: tar xfz ).

Now you'll find (almost) all the needed sources for your toolchain. What's missing? Yep, the FreeBSD sources!
To make it easier for you, I've uploaded them all to my server:

Just download them for now, don't extract them anywhere yet.

Now we can go on with compiling the binutils.
Go to the directory where your downloaded archives are in and type the following:
Code:
tar xfz binutils-2.23.1.tar.gz
mkdir -p build/binutils
cd build/binutils
../../binutils-2.23.1/configure --enable-libssp --enable-gold --enable-ld --target=x86_64-pc-freebsd7.4 --prefix=/usr/freebsd-gcc
make
make install
This will build and install binutils to /usr/freebsd-gcc/.

Now you should extract the FreeBSD files you've downloaded earlier (fbsd7.4-libs-headers.tar.bz2).
Move the two folders in there (lib and include) to /usr/freebsd-gcc/x86_64-pc-freebsd7.4/.

After doing this, you're ready for compiling GCC!

First, we'll need to compile GMP as it's a necessary library for us.
Go back to the tmp directory in which your downloaded stuff is and do the following:
Code:
tar xfj gmp-5.1.1.tar.bz2
mkdir -p build/gmp
cd build/gmp
../../gmp-5.1.1/configure --prefix=/usr/freebsd-gcc --enable-shared --enable-static --enable-mpbsd --enable-fft --enable-cxx --host=x86_64-pc-freebsd7.4
make
make install
This will compile and install GMP 5.1.1.

Now you'll need MPFR:
Code:
tar xfj mpfr-3.1.2.tar.bz2
mkdir -p build/mpfr
cd build/mpfr
../../mpfr-3.1.2/configure --prefix=/usr/freebsd-gcc --with-gnu-ld --with-gmp=/usr/freebsd-gcc --enable-static --enable-shared --host=x86_64-pc-freebsd7.4
make
make install
This will compile and install MPFR 3.1.2.

And.. now.. the last thing before you can go on with compiling your beloved GCC: compile and install MPC:
Code:
tar xfz mpc-1.0.1.tar.gz
mkdir -p build/mpc
cd build/mpc
../../mpc-1.0.1/configure --prefix=/usr/freebsd-gcc --with-gnu-ld --with-gmp=/usr/freebsd-gcc --with-mpfr=/usr/freebsd-gcc --enable-static --enable-shared --host=x86_64-pc-freebsd7.4
make
make install
After doing all this, you're ready to compile GCC 4.7.3.
Because we do not want to replace our system stuff, we'll install GCC inside our toolchain directory.

Code:
tar xfj gcc-4.7.3.tar.bz2
mkdir -p build/gcc
cd build/gcc
../../gcc-4.7.3/configure --without-headers --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --disable-nls --enable-libssp --enable-gold --enable-ld --target=x86_64-pc-freebsd7.4 --prefix=/usr/freebsd-gcc --with-gmp=/usr/freebsd-gcc --with-mpc=/usr/freebsd-gcc --with-mpfr=/usr/freebsd-gcc --disable-libgomp
LD_LIBRARY_PATH=/usr/freebsd-gcc/lib make
make install
This will take several minutes!

After this is done, you're ready to use your FreeBSD-GCC under Linux!
Go on and test it!

Create a file 'test.c':
Code:
#include <stdio.h>

int main(int argc, char *argv[])
{
printf("It works!");
return 0;
}
Now try compiling it using your Linux GCC:
Code:
gcc test.c -o test-linux
file test-linux
And now using your Linux G++
Code:
g++ test.c -o test-linux-++
file test-linux-++
(should return this for Linux)
Code:
test-linux: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xe6069259f37d48488b519640f5136e2bd85950de, not stripped
Worked? Alright.. let's hope it's the same for our FreeBSD GCC!

Code:
LD_LIBRARY_PATH=/usr/freebsd-gcc/lib /usr/freebsd-gcc/bin/x86_64-pc-freebsd7.4-gcc test.c -o test-freebsd
file test-freebsd
Aaaand for our G++:
Code:
LD_LIBRARY_PATH=/usr/freebsd-gcc/lib /usr/freebsd-gcc/bin/x86_64-pc-freebsd7.4-g++ test.c -o test-freebsd-++
file test-freebsd-++
(should return this for FreeBSD)
Code:
test-freebsd: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), dynamically linked (uses shared libs), for FreeBSD 7.4, not stripped
If everything worked well, you should have 2 Linux binaries and 2 FreeBSD binaries
Good luck!

Best regards, Nico

Used for reference
nico_w is offline  
Thanks
4 Users
Old 08/04/2013, 23:21   #2

 
elite*gold: 0
Join Date: Feb 2008
Posts: 2,754
Received Thanks: 1,748
Nett, ich war immer zu faul rumzuprobieren.

Nur eine Frage:
Warum zum Teufel FreeBSD 7.4? Das ist doch schon mehr als überholt, bekommt nicht einmal mehr Sicherheitsupdates o,ô
Computerfreek is offline  
Old 08/05/2013, 13:54   #3

 
nico_w's Avatar
 
elite*gold: 0
Join Date: Aug 2008
Posts: 5,150
Received Thanks: 10,486
Ist nur das Target-OS da mir die Libs und Includes für neuere Versionen fehlten.. die kompilierten Sachen laufen auch unter jeder neuen Distribution problemlos.
nico_w is offline  
Old 08/23/2013, 01:35   #4

 
elite*gold: 0
Join Date: Feb 2008
Posts: 2,754
Received Thanks: 1,748
Nebenbei wäre es noch schön, wenn du die Quelle mit angegeben hättest.
Die nämlich die folgende ist:
Falls dem nicht so sein sollte natürlich sorry, sieht aber sehr danach aus.

/e:
Funktioniert bei mir auch leider nicht so einwandfrei.
Ich benutze ein Linux Mint 15, akuellste Version. Bei den Tools musste ich ein paar mal nachkorrigieren und beim GCC bin ich dann endgültig gescheitert - leider.
Computerfreek is offline  
Old 10/17/2013, 13:21   #5

 
nico_w's Avatar
 
elite*gold: 0
Join Date: Aug 2008
Posts: 5,150
Received Thanks: 10,486
Das Tutorial hatte ich teilweise als Referenz verwendet, hatte den Link nicht mehr da.. so wie es da stand funktionierte es jedenfalls nicht vollständig bei mir :s
Ich hatte auch ne Debian-Distribution verwendet, ich wüsste nicht weshalb es unter Mint nicht laufen sollte..
nico_w is offline  
Reply


Similar Threads Similar Threads
[Help]FreeBSD auf Linux/... installieren
06/22/2013 - Metin2 Private Server - 3 Replies
Hallo, Wie oben beschrieben habe ich mir einen Root Server gekauft. Doch da ich nicht viel Ahnung hatte habe ich mit einen Server ohne FreeBSD gekauft. Den Support hab ich schon nachgefragt, sie meinen es geht leider nicht. Ich habe alle tuts aus Epvp ausprobiert & das was Google ausspuckt alles ging nicht oder ich habe was falsch gemacht habe keine Ahnung.Meine Frage an euch: Kann mir jemand dabei helfen ? Ich habe diese Systeme zur Verügung, habe nicht alle getestet: Debian 6.0...
Linux zu FreeBSD hilfe
02/02/2011 - Metin2 Private Server - 2 Replies
Hallo Community, wie der Threadname schon sagt benötige ich freiwillige Hilfe bei dem berüchtigten Tool Depenguinator ich habe schon viel darüber gelesen, in FreeBSD-Foren und auf andere Emulatorenseiten wie diese. Bevor ich nach Eure Hilfe frage möchte ich betonen das ich jegliche Sufu benutz habe und mehr als einmal fündig geworden aber leider immerwieder gescheitert bin, außerdem möcte ich zugeben das ich mich sehr schwer getan habe mich zu überwinden nach Hilfe zu fragen da ich sehr...
Linux -> FreeBSD
01/15/2011 - Metin2 Private Server - 6 Replies
Hey Com, könnte mir vllt jemand helfen meinen Linux-Rootserver zu einem FreeBSD-Rootserver zu machen. Ich habe das Tutorial von aiiR7 gelesen aber es nicht hinbekommen. Auch das von H²O habe aber auch das nicht hin bekommen. Wer mir helfen kann bekommt dann später wenn Server läuft einen -Account.
[Service]Serverinstallation auf FreeBSD/FreeBSD auf Linux/Debian
12/28/2010 - Metin2 Private Server - 23 Replies
Huhu community, ich möchte euch ab jetzt meinen Service anbieten. Das mache ich aus dem Grund, weil ich gerne Leuten helfen möchte die vielleicht nicht so gut mit den Serverfiles bzw. einem Root Server umgehen können. Jetzt stellt ihr euch sicherlich die Frage, was mache ich genau - und wie viel kostet es - kostet es überhaupt was? Also erstmal zur Ersten frage. Was mache ich genau und wie sieht der Service aus?
FreeBSD Linux?
08/10/2010 - Metin2 Private Server - 0 Replies
Hay liebe (auch böse) Elitepvpers, Ich habe folgendes Problem mit meinem Server: Alle Anbieter bieten nur Linux und Windows an, das aufsetzen anderer Betriegssysteme ist erlaubt. Das Problem besteht in dem Wechsel von Linux 32bit, alle Images verfügbar, auf FreeBSD 7.1 32bit. Ich hoffe ihr könnt mir helfen, LG: figo96



All times are GMT +1. The time now is 02:58.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.