How to compile in Linux for Windows

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.
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.
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
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.
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.
Thank you very much! -static worked. Thanks, again!
It works, but just a simple input and output takes 8.5 mb on .exe. Is that normal?
it is normal, and you can use optimizations
What do you mean with "optimizations"? How can i optimize it?
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.