简体   繁体   中英

g++ cross compile to windows from linux

Im trying to cross compile a c++ application to windows from linux. I want to be able to use the normal g++ compiler as I have always used.

I tried looking online for help on this issue and found only mingw or clang stuff or stuff with a long complex setup.

Is there like a one line command I can use like g++ -windows to get it to build a windows executable right there. My code doesnt use any windows libaries so should compile just fine.

Thanks for the help.

Is really not that hard. The only thing you need to do is install g++-mingw-w64 with:

sudo apt install g++-mingw-w64 -y

After that, the only thing you need to do is compile with:

x86_64-w64-mingw32-g++ hello.c -o hello.exe

That is going to give you a 64-bit executable for windows that just runs. That's how I do it and I haven't had any problems.

If you want a 32-bit executable just do:

i686-w64-mingw32-g++ hello.c -o hello.exe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM