Thread: Cross-compiling a Windows command-line application

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    30

    Lightbulb Cross-compiling a Windows command-line application

    Hello!

    I have been learning C for a few months and I've worked my way through the tutorials
    in this website. I've written a simple command-line application that reads two files and
    do some simple operations, such as copying some data from the source to the target
    file. I'm using Bloodshed's Dev-cpp compiler and I would like to know if there's a possibility
    to compile it for the Mac platform.

    My program uses only basic stdio and string functions, such as getc, putc, fread, fwrite,
    fseek, strcmp and so on. It's very simple. So, is there a possibility to compile it for MAC or I
    would I need to make many modifications to my source code? Where can I read more about this?

    Thanks in advance!

  2. #2
    * noops's Avatar
    Join Date
    Jun 2008
    Posts
    108
    As far as I am aware you need to compile it on a mac itself.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Compiling it on a mac itself is the easy way, of course -- if everything you're using is in a standard library like stdio.h and string.h, then you won't need to change the code.

    It's certainly possible to compile for other operating systems than the one you're on, and gcc (the compiler under the hood for bloodshed) certainly can do it -- but I don't know if it can do it "out of the box". I've never tried, so I can't say; my gut guess is "no". (You can always try I suppose; you could read the gcc manual at gcc.gnu.org for the compiler switches.)

  4. #4
    Registered User
    Join Date
    Aug 2008
    Posts
    30
    Sorry, I forgot to mention that I don't have access to a MAC, so I would have to compile it on my x86 machine. I'll read the gcc documentation to see if this is possible, but if anyone wants to share some experiences on this issue, feel free to post it .

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    When cross-compiling, you will need:
    1. A compiler/linker that can generate code for the target system, but that runs on the host machine. I believe gcc can be made to do this, but I'm not sure you can easily compile gcc with Windows compiler (the best option is going to be either Cygwin or gcc-mingw - but you also need all the other components needed to compile gcc). Of course, there MAY be a compiler out there already made for this purpose - but finding it may turn a bit difficult (and for commercial options - if there are any, you are probably better off finding one of the less expensive models of Mac).

    2. A C library for the target system. This is probably glibc on a Mac. I expect you can get a copy of that from somewhere.

    I'm sure all of this is achievable, but if you want to make your life easier, you would have two better options:
    1. Get a Mac.
    2. Install Linux on your PC, and build a cross-compiler for Mac on that machine - that is a fair bit easier to achieve than to build a cross-compiler for Windows - it can probably be achieved in somewhere between 1-3 days (1 day being the "everything works fine by just saying 'create cross compiler for Mac'", 3 days would be "some further attempts has to be done, but solvable" - a worst case scenario is that a Mac compiler doesn't for some bugs or other problems build on a Linux machine either).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Aug 2008
    Posts
    30
    I'll go for the Linux option . Should I go for a minimalist distro or do I need something more complete? A specific recommendation would be welcome.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by papagaio View Post
    I'll go for the Linux option . Should I go for a minimalist distro or do I need something more complete? A specific recommendation would be welcome.
    Whatever you fancy - as long as it's able to run gcc for x86 (or PowerPC if it's older Mac's you are writing you code for) - and aside from those specifically targeting small embedded systems, I think all Linux distros would do that. The last time I installed Linux it was a Fedora version, but others are probably just as good.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inserting a swf file in a windows application
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 05-03-2009, 11:29 AM
  2. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 09:59 AM
  3. Compiling for other OSs on a Windows machine
    By sean in forum Tech Board
    Replies: 14
    Last Post: 07-25-2004, 07:55 PM
  4. MFC dialog application - how to update two windows
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 10-23-2001, 01:54 AM
  5. Problem with Borland 5.5 Compiling Windows Programs
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 08-28-2001, 09:04 AM