• Advertisement
Sign in to follow this  

Building a cross-compiler

This topic is 4262 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. Can anyone help me with this? I need to build a compiler that compiles code for Lunix systems in windows, i mean, while in windows, compile code that executes on linux. This is a cross-compiler. How can i build one?

Share this post


Link to post
Share on other sites
Advertisement
You start by learning how the ELF format works, then you just use standard file IO to write an ELF file, just like you would on Linux. Of course you can't run the ELF file on Windows which uses PE files (the recent versions of Windows at least). With an emulator you'll be able to run it on any platform.

Share this post


Link to post
Share on other sites
Quote:
Original post by CTar
You start by learning how the ELF format works, then you just use standard file IO to write an ELF file, just like you would on Linux. Of course you can't run the ELF file on Windows which uses PE files (the recent versions of Windows at least). With an emulator you'll be able to run it on any platform.


Heh, there are a couple of bigger differences than the binary format, and I get the feeling you only wrote this to look clever :)

Anyway, to OP; do you really mean you want to BUILD a cross-compiler, or is it enough to INSTALL one that already exists? In the latter case, there are gcc's compiled for windows that will output linux binaries.

Share this post


Link to post
Share on other sites
There are instructions for this all over the web. One of the more straightforward ones is here. If that one does work for you you can find dozens of instructions by googling for "cross compiler windows linux".

Share this post


Link to post
Share on other sites
Quote:
Original post by tok_junior
Heh, there are a couple of bigger differences than the binary format, and I get the feeling you only wrote this to look clever :)

No, I didn't write it to "look clever" (feel free to point out how dumb I really am if you feel I am being dumb in some way). What are does "bigger" differences? Of course he can't link to the Windows libraries, he need to do everything "the Linux way". There shouldn't be any difference in writing a compiler for Linux on Windows and writing a compiler for Linux on Linux, the only difference would be if the compiler itself wasn't cross-platform (GUI, Win32 libraries, threading etc.).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i am really not knowledgable about the subject but you might want to have a look at the phoenix compiler project from microsoft. looks like it could be your best starting point.

Share this post


Link to post
Share on other sites
Ops. I think i didnt explained very well...Sorry, its fault of my terrible english. I dont want to MAKE, nor program a compiler....not now. I just want to build it, i mean, compile the gcc toolchain and all the libraries needed to make console application fro linux, while being in windows.

Share this post


Link to post
Share on other sites
WARNING: THIS MAY NOT WORK AT ALL! this is just how I would imagine you could get something going based on how you get crosscompiler from Linux to Windows and from Windows and Linux to PSP.

Install Cygwin, download the source code for binutils and gcc,
unpack both.

go into cygwin and configure binutils with

./configure --host=i686-pc-cygwin --build=i686-pc-cygwin --target=i686-pc-linux-gnu --disable-nls

make and install, then make sure you have the path to the new binaries (usually /usr/local/i686-pc-linux-gnu/bin or /usr/local/bin) on your PATH, then configure GCC with:

./configure --host=i686-pc-cygwin --build=i686-pc-cygwin --target=i686-pc-linux-gnu --with-gnu-ld --with-gnu-as --disable-nls

then make with:

Make LANGUAGES="C C++"

You may need to compile newlib or more likely glibc between compiling binutils and gcc, I am not sure.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement