Results 1 to 5 of 5

Thread: Compile C programs for windows on Linux

  1. #1
    Join Date
    Sep 2006
    Beans
    21

    Compile C programs for windows on Linux

    Hi everyone, I've been writing some OpenGL programs in C under Ubuntu, and it works great, apart from the slow graphics performance. I wanted to try some of my programs on a windows platform to show to some friends and see what they're really capable of. Well anyway, I was able to dump my code into MS Visual Studio C++ compiler and EVENTUALLY get it to compile and run. Except that compiler is not ISO C and is way too picky.

    So instead of sifting through my code to make it work for the Windows compiler, is there a way I can compile exes on Linux for Windows? I did some research before and found some people using Cygwin to do it, but I'm not sure if Cygwin dumps exes. Thanks!

  2. #2
    Join Date
    Apr 2006
    Location
    Seattle
    Beans
    2,893
    Distro
    Ubuntu Development Release

    Re: Compile C programs for windows on Linux

    Cygwin is a Windows program that dumps .exe's, but that is the problem: it (the compiler) only runs on Windows. Cygwin is essentially a Linux emulator for Windows when used correctly.

    To compile Windows programs from Linux (aka cross-compiling) just install the mingw32 package. Now, instead of using gcc (or g++) to compile, you use i586-mingw32msvc-gcc (or i586-mingw32msvc-g++ if you use C++ code).

    So, to compile main.c into program.exe, run this:
    Code:
    i586-mingw32msvc-gcc -o program.exe main.c
    Hope I wasn't too confusing with that description.

    Jacob
    Last edited by jpeddicord; December 15th, 2006 at 03:59 AM.

  3. #3
    Join Date
    Oct 2005
    Location
    Helsinki, Finland
    Beans
    1,351

    Re: Compile C programs for windows on Linux

    Can be done. I just compiled a c++ game project for school (multiplayer tetris with network play ) for windows in ubuntu using mingw. The package that you need is "mingw32".

    This page has some info to get you started.

  4. #4
    Join Date
    Sep 2006
    Beans
    21

    Re: Compile C programs for windows on Linux

    Well this seems to be exactly what I was looking for, except I don't know how to link to the required GL libraries.

    I tried i586-mingw32msvc-gcc tetris.c -o tetris.exe -lglu32
    and I get a shiat loat of errors. (mostly undeclareds or previous definitions..) The first one points to my #include <GL/glut.h> statement. I tried changing that to just #include <glut.h> and the same thing happens.

    I don't know much about how compiling actually works, other than it works for a linux binary, nor the CVS stuff talked about on that Wiki page. I didn't use SDL or widgets or anything special when programming the thing, just glut, and I have no idea what the heck ./configure is.

    So yeah, I just need one makefile or a statement that will do the trick. Nothing special.

  5. #5
    Join Date
    Jul 2005
    Beans
    52

    Re: Compile C programs for windows on Linux

    You can't link the Linux GL library to the executable. You need to have the windows GL libraries to link against. You will have to some googling on how this works.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •