Building Linux Binaries under FreeBSD with GCC

Building Linux Binaries under FreeBSD with GCC

Post by Damien Bergamin » Thu, 16 Jan 2003 23:18:57



I want to build linux binaries from sources with gcc under FreeBSD.
AFAIK, there are two solutions to solve this problem:
1) doing some kind of cross compilation with native gcc under FreeBSD
2) installing linux gcc (with linux emulation) under FreeBSD
Does anyone here experienced one or both of these solutions ?

Thanks in advance,
Damien

 
 
 

Building Linux Binaries under FreeBSD with GCC

Post by Tom Mattman » Fri, 17 Jan 2003 02:04:20


DB> I want to build linux binaries from sources with gcc under FreeBSD.
DB> AFAIK, there are two solutions to solve this problem:
DB> 1) doing some kind of cross compilation with native gcc under FreeBSD

I'm not sure if this is easily achievable, since compilation is only one
step when building a binary. Linking is another issue. Linuces are usually
based on glibc, *BSDs not.

DB> 2) installing linux gcc (with linux emulation) under FreeBSD

Does this make any difference from using a "native" compiler? This does
not solve the linking problem. And unless you build statically linked
binaries, you still have trouble with supporting various distro's based on
different glibc versions. It's probably not worth the hassle...

Shipping the source has a long tradition in the *nix world. :-) If you
cannot ship the source for any reasons, it is probably better to have a
Linux development environment built up with the distro you'd like to
support.

BTW: Is ELF the same on BSD and Linux?

Cheers,
Tom
--
 mailto: tom DOT mattmann AT terreactive DOT ch      spamto: /dev/null
 ---------------------------------------------------------------------
 "It is better to know some of the questions than all of the answers."
                                                      -- James Thurber

 
 
 

Building Linux Binaries under FreeBSD with GCC

Post by Steven G. Kar » Fri, 17 Jan 2003 02:35:21




Quote:> I want to build linux binaries from sources with gcc under FreeBSD.
> AFAIK, there are two solutions to solve this problem:
> 1) doing some kind of cross compilation with native gcc under FreeBSD
> 2) installing linux gcc (with linux emulation) under FreeBSD
> Does anyone here experienced one or both of these solutions ?

You want to do 2).  See /usr/ports/devel/linux_devtools.

--
Steve
http://troutmask.apl.washington.edu/~kargl/

 
 
 

Building Linux Binaries under FreeBSD with GCC

Post by Ivan Vora » Fri, 17 Jan 2003 03:43:06




>> DB> I want to build linux binaries from sources with gcc under FreeBSD.
>> DB> AFAIK, there are two solutions to solve this problem:
>> DB> 1) doing some kind of cross compilation with native gcc under FreeBSD

>> I'm not sure if this is easily achievable, since compilation is only one
>> step when building a binary. Linking is another issue. Linuces are
>> usually based on glibc, *BSDs not.

>> DB> 2) installing linux gcc (with linux emulation) under FreeBSD

>> Does this make any difference from using a "native" compiler? This does
>> not solve the linking problem. And unless you build statically linked
>> binaries, you still have trouble with supporting various distro's based
>> on different glibc versions. It's probably not worth the hassle...

>> BTW: Is ELF the same on BSD and Linux?

AFAIK, in there lies most of the problems involved: ELF is exactly the same
for Linux and FreeBSD binaries, and it was not originaly designed to support
more then one "subsystem" or ABI on a single OS. There is some special magic
involved in recognizing which type (FreeBSD or Linux) the executable is. So,
it would be very confusing for compiler & linker to understand the subtle
differences. I am not an expert, but IMO if you must build Linux executables
under FreeBSD, you sould use the whole Linux toolchain (compiler, linker &
libraries) running under Linux emulation. Even so, you will probably have to
fiddle with separating the FreeBSD environment (includes, libraries) from
the Linux one while building.

(I myself would like to know more about this subject, so if anybody has more
insight, please follow up on this).

--
--
Do not meddle in the affairs of sysadmins, for they can make your life
miserable by doing nothing.

 
 
 

Building Linux Binaries under FreeBSD with GCC

Post by Steve O'Hara-Smit » Fri, 17 Jan 2003 03:28:36


On Wed, 15 Jan 2003 15:18:57 +0100

DB> I want to build linux binaries from sources with gcc under FreeBSD.
DB> AFAIK, there are two solutions to solve this problem:
DB> 1) doing some kind of cross compilation with native gcc under FreeBSD
DB> 2) installing linux gcc (with linux emulation) under FreeBSD
DB> Does anyone here experienced one or both of these solutions ?

        Look into /usr/ports/devel/linux-devtools(-7).

--
C:>WIN                                      |     Directable Mirrors
The computer obeys and wins.                |A Better Way To Focus The Sun
You lose and Bill collects.                 |  licenses available - see:
                                            |   http://www.sohara.org/

 
 
 

Building Linux Binaries under FreeBSD with GCC

Post by Gunther Nik » Fri, 17 Jan 2003 17:46:53



>>> BTW: Is ELF the same on BSD and Linux?

> AFAIK, in there lies most of the problems involved: ELF is exactly the same
> for Linux and FreeBSD binaries,

  No, it never was.

Quote:> and it was not originaly designed to support more then one "subsystem" or
> ABI on a single OS.

  It got enhanced with EI_OSABI and EI_ABIVERSION which is supposed to help
  (maybe because the information in an ELF file were not enough?)

Quote:> There is some special magic involved in recognizing which type (FreeBSD or
> Linux) the executable is.

  Not really. Usually there is a special section (PT_NOTE). I don't call
  that magic. However, earlier FreeBSD did use a * hack to differentiate
  between a FreeBSD and Linux ELF binary.

Quote:> IMO if you must build Linux executables under FreeBSD, you sould use the
> whole Linux toolchain (compiler, linker & libraries) running under Linux
> emulation.

  Thats one solution. A different one is to build a linux-toolchain
  completely under FreeBSD. Thats called cross-compiling.

Quote:> Even so, you will probably have to fiddle with separating the FreeBSD
> environment (includes, libraries) from the Linux one while building.

  No. The linux binaries run in their own world: their "root" is
  /usr/compat/linux.

Quote:> (I myself would like to know more about this subject, so if anybody has
> more insight, please follow up on this).

  Using ports is probably the best solution.

  Gunther

--
Linux is only free if your time has no value
 - Jamie Zawinsky

 
 
 

Building Linux Binaries under FreeBSD with GCC

Post by Ivan Vora » Fri, 17 Jan 2003 23:51:06




>>>> BTW: Is ELF the same on BSD and Linux?

>> AFAIK, in there lies most of the problems involved: ELF is exactly
>> the same for Linux and FreeBSD binaries,

>   No, it never was.

I'm somewhat interested in this subject. Are there any web resources where
the differences are explained?

--
--
Ashes to ashes, DOS to DOS

 
 
 

Building Linux Binaries under FreeBSD with GCC

Post by Kurt Jaeg » Sat, 18 Jan 2003 02:19:15


Hi!

Quote:>>> BTW: Is ELF the same on BSD and Linux?
>AFAIK, in there lies most of the problems involved: ELF is exactly the same
>for Linux and FreeBSD binaries, and it was not originaly designed to support
>more then one "subsystem" or ABI on a single OS. There is some special magic
>involved in recognizing which type (FreeBSD or Linux) the executable is. So,
>it would be very confusing for compiler & linker to understand the subtle
>differences. I am not an expert, but IMO if you must build Linux executables
>under FreeBSD, you sould use the whole Linux toolchain (compiler, linker &
>libraries) running under Linux emulation. Even so, you will probably have to
>fiddle with separating the FreeBSD environment (includes, libraries) from
>the Linux one while building.

Works easy, if you read the

http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/linuxemu.html

on how it was configured.

--
MfG/Best regards, Kurt Jaeger                                  17 years to go !

Ruppmannstr. 27    fax +49 711 90074-33
D-70565 Stuttgart  mob +49 171 3101372

 
 
 

Building Linux Binaries under FreeBSD with GCC

Post by Matt M Syk » Sat, 18 Jan 2003 08:41:08



> I want to build linux binaries from sources with gcc under FreeBSD.
> AFAIK, there are two solutions to solve this problem:
> 1) doing some kind of cross compilation with native gcc under FreeBSD
> 2) installing linux gcc (with linux emulation) under FreeBSD
> Does anyone here experienced one or both of these solutions ?

> Thanks in advance,
> Damien

My first inclination would be to build the cross-compiler from source.
The process isn't as difficult as one would think.  It goes something
like

./configure --build=i386-freebsd --host=i386-freebsd
--target=i386-linux --prefix=/usr/local/cross-tools --languages=c,c++

for each of binutils, gcc, gdb (and newlib if you want to avoid
license issues).

"build" is place you are making the cross-compiler, "host"
is where to cross-compiler will live, and "target" is what
type of stuff the cross-compiler will spit out.

I made a freebsd-to-arm cross-compiler this way.

http://www.objsw.com/CrossGCC

Also, just look around google with "gcc+cross+compiler+build" etc.

Matt

 
 
 

1. gcc 4.1.1 build under Intel Solaris 10 does not build gcc

This is strange. gcc compiled fine (i did it yesterday on Sparc, and
today on Intel).

While a call to "g++ -v" tells me that 4.1.1 is invoked (using the
standard prefix /usr/local/bin)
the "gcc" executable is not installed. It is still the 3.3 that i
installed as a package from sunfreeware.com

Any ideas where i can find the gcc ?

I did a simple "configure ; make ; make install" without any parameters.

2. AutoClient Question ..

3. can not build static binary with 64 bit gcc

4. one hard drive or two?

5. building v8 solaris binaries with gcc

6. How the *&^#^&%# do you set the $PATH

7. gcc 2.7.2 in libg++ 2.7.2 build on FreeBSD 2.1.5

8. will toshiba 2155cds work with linux

9. gcc binaries/expect binaries?

10. Where are the tgz/binary/i386/gcc/ binary release for KDE Beta 4????

11. HOWTO build/install GCC 3.1 from SRPM w/o replacing GCC 2.96 ?

12. gcc-2.7.0 (usr/bin/gcc: cannot execute binary.)

13. Mathematica Linux binaries with FreeBSD Linux emulation