Generate a Windows executable under Linux with gcc/g++

This is a discussion on Generate a Windows executable under Linux with gcc/g++ within the Linux Programming forums, part of the Platform Specific Boards category; I'm sure this question has already been asked before but I couldn't find anything on it so... Can someone tell ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    204

    Generate a Windows executable under Linux with gcc/g++

    I'm sure this question has already been asked before but I couldn't find anything on it so...

    Can someone tell me if it's possible and how to do it? Thanks.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,443
    Quickest way would be to run dev-c++ within WINE.

    With some effort/skill, it should be possible to install gcc hosted on linux and producing win32 executables (probably start by looking at what mingw do).

    What you need to be looking for are called cross-compilers, which run on machine 'a' and produce programs for machine 'b'. It's usually the preserve of the embedded programming community, since most desktop types just compile and execute on the same machine.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jul 2005
    Posts
    33
    You need these packages

    xmingw-binutils Tools necessary to build Win32 programs
    xmingw-gcc The GNU Compiler Collection - i386-mingw32msvc-gcc only
    xmingw-runtime Free Win32 runtime and import library definitions
    xmingw-w32api Free headers and libraries for the Win32 API

    I dunno where to find them though

    Then in a console type this (make sure you are logged in as the same user that will do the compiling)

    alias g++w32="/opt/xmingw/bin/i386-mingw32msvc-g++"

    Now you are ready to compile your cpp for windows:

    i386-mingw32msvc-g++ ./<cppname>.cpp -o <nameoffile>.exe

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,046
    You might be able to ask someone with Windows to compile your program for you.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User Jaqui's Avatar
    Join Date
    Feb 2005
    Posts
    416
    which tool did you use to create the code?
    most of the linux tools are linux specific.

    but qt is cross platform.
    if you can pull it into qt designer then save it, with project options including windows support, gcc's make will be able to use the win32 targets to cross compile.

    much easier than installing cygwin / mingw, or finding someone with windows AND a compatable compiler.
    ( most windows compilers are not compatable wiith gcc. )

  6. #6
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by Jaqui
    much easier than installing cygwin / mingw, or finding someone with windows AND a compatable compiler.
    ( most windows compilers are not compatable wiith gcc. )
    cygwin is for making linux stuff useable in windows... and Dev-C++ uses GCC... or you could just have them use GCC... (there's a MingW port for windows)

    they don't need a compiler compatible with GCC anyway if your code is standard... if you used all standard coding you should just be able to pass it on to any windows user (there's a few out there... just ask around) with any (c/c++) compiler and they should be able to give you the binary.

    Quickest way would be to run dev-c++ within WINE.

    what about running the MingW port of GCC within WINE? would that work?
    Last edited by major_small; 07-15-2005 at 05:20 AM.
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  7. #7
    Registered User Jaqui's Avatar
    Join Date
    Feb 2005
    Posts
    416
    it might, but since qt designer is available with most distros, and has the cross platform support, it's probably the easiest for enabling the cross compiling that gcc and g++ can do.

    if it's not installed, installing a linux app and associated libs is far simpler than tweaking wine to run an app that is designed to use gcc and g++ under mingw in windows.

    the hardest effective way would be to manually edit the makefile to add win32 targets to it.
    then, at the bash prompt, you would only have to enter the make -windows target name

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 03:44 AM
  2. Why Linux, for the average user?
    By Hunter2 in forum A Brief History of Cprogramming.com
    Replies: 32
    Last Post: 07-07-2006, 02:36 PM
  3. Why can't Windows run Linux binary executables?
    By Kleid-0 in forum Tech Board
    Replies: 30
    Last Post: 12-04-2005, 10:44 PM
  4. Erm...so what DOES Linux do that Windows doesn't?
    By 7smurfs in forum Tech Board
    Replies: 19
    Last Post: 09-09-2005, 03:04 PM
  5. linux and windows lookup host processes
    By Lynux-Penguin in forum Tech Board
    Replies: 0
    Last Post: 08-31-2003, 11:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21