4

I'm using Ubuntu and I use Code::Blocks as my IDE, I'm still a student and my professor wants us to write and compile some c++ programs and give him the exes to check them

Is there a way for me to generate exe files on my Linux os ?

ps: I'm new to Linux so take it easy on me.

Thanks

Ma7moud
  • 49
  • 1
  • 3
  • 1
    Learn about cross-compiling. The tools exist in Ubuntu too. – Dirk Eddelbuettel Dec 16 '15 at 18:15
  • If you build your C++ code, you'll get a binary that can run on _similar_ systems (like other people who use the same version of Ubuntu). If you mean you want to build an `.exe` like for Windows, you'll have to cross-compile or build your code in Windows. A first thing to look at would be the [`mingw64-w64` package](http://packages.ubuntu.com/search?keywords=mingw-w64) in Ubuntu. – wkl Dec 16 '15 at 18:16
  • googling "cross compile from linux to windows" yielded many interesting results. – Richard Hodges Dec 16 '15 at 18:18
  • You [need a cross-compilation](http://stackoverflow.com/a/897303) You can use mingw tool chain, [check this answer](http://stackoverflow.com/a/2034007/1566267) for instructions. – John_West Dec 16 '15 at 18:19
  • Note only: actually linux can run .exe files. (I'm not sure if linux c++ compilers build exe files, but for instance I compiled a lot of pascal programs on Ubuntu, and it gave me exe, but this was long time ago) – Lasoloz Dec 16 '15 at 18:20
  • @Lasoloz No, a) they doesn't build exe files without cross-compilation b) you probably successfully run exe under linux because it had automatically started under some emulator-app like wine. – John_West Dec 16 '15 at 18:22
  • With Wine you don't even need "cross-compilation" (a compiler aware of running on a different platform than it is compiling for). You can install a Windows compiler (with supporting files and tools) on Linux and run it under Wine. – JSF Dec 16 '15 at 18:26
  • Possible duplicate of [Howto compile for Windows on Linux with gcc / g++?](http://stackoverflow.com/questions/2033997/howto-compile-for-windows-on-linux-with-gcc-g) – mpromonet Dec 16 '15 at 21:30

1 Answers1

4

You need a cross-compilation. You can use mingw tool chain, if your want 32bit Windows application, install mingw32. Here are the detailed instructions for using it with IDE CodeBlocks.

If you want to build 64-bit applications, try mingw-w64 fork.

Also, then you could run the compiled application (or, even some native windows applications, compiled on Windows) in Linux under Wine:

sudo apt-get install wine
wine myapp.exe
Community
  • 1
  • 1
Ankur Jyoti Phukan
  • 785
  • 3
  • 12
  • 20