How to compile in Linux for Windows

Jun 21, 2015 at 4:35pm
Hi! :) I just moved on linux few days ago and I want to compile something for Windows. I wrote the code in Code::Blocks thinking that it will compile it as an exe, it says it can't find conio.h windows.h etc... How can i solve this? I am thinking to open it with Wine, see if it works and then run it on a Windows PC. Thanks.
Jun 21, 2015 at 4:45pm
conio.h is not part of standard C++. You don't want to have it in your code.

Nevertheless, a compiler will by default compile binaries for the native platform. In order to compile for non-native platform, one must use a cross-compiler that has necessary libraries of the target platform. There should be (Windows) cross-compilers available for some Linux distributions. They might have "mingw" in their name.
Jun 21, 2015 at 6:22pm
get MinGW that is compiled for linux that target's win32 executables and use it
and get
http://sourceforge.net/projects/conio
then compile your project with it!
Last edited on Jun 23, 2015 at 12:15am
Jun 22, 2015 at 7:36am
I tried to compile something using i686-w64-mingw32-g++ hello32.cpp -o hello32.exe
But when i run it on Win XP 32 bits i get the next error
This application has failed to start because libstdc++-6.dll was not found. Re-installing the application may fix this problem.
Jun 22, 2015 at 8:36am
Try -static.

If that doesn't work, just go into your mingw32/bin folder and copy the dll's that the exe tells you into the folder with the exe.
Jun 22, 2015 at 8:59am
Thank you very much! -static worked. Thanks, again!
Jun 22, 2015 at 9:07am
It works, but just a simple input and output takes 8.5 mb on .exe. Is that normal?
Jun 23, 2015 at 12:17am
it is normal, and you can use optimizations
Jun 23, 2015 at 10:04am
What do you mean with "optimizations"? How can i optimize it?
Jun 23, 2015 at 10:19am
It is not recommended to do optimizations during development, but when you do start caring about performance you can use optimization flags.

The speed performance flags are:

-O is the lowest optimization,
-O1 is more optimized than -O
-O2 is more optimized than -O1
-O3 is the highest optimization

And there are other optimization flags:

-s strip all binary symbols for size
-Os optimize for size

If you want a slightly faster compile you could put all the dll's with the exe, but it really isn't anything.
Topic archived. No new replies allowed.