Cross-Compiling for Windows on Linux Using GCC/G
This discussion revolves around achieving cross-compilation of C (g ) code from Linux for Windows executables. The question arises from the desire to create standalone executables on Linux that contain all necessary dependencies.
The solution emerges from utilizing mingw32, a package available for Linux. With mingw32, developers can cross-compile and link Windows applications.
For Ubuntu users, MinGW is conveniently accessible through the repositories:
$ apt-cache search mingw [...] g++-mingw-w64 - GNU C++ compiler for MinGW-w64 gcc-mingw-w64 - GNU C compiler for MinGW-w64 mingw-w64 - Development environment targeting 32- and 64-bit Windows [...]
To initiate cross-compilation, simply modify the compiler command to 'x86_64-w64-mingw32-gcc-win32', ensuring compatibility with Windows targets.
By leveraging mingw32's capabilities, Linux users can seamlessly create statically compiled Windows executables without the need for a direct Windows environment.
The above is the detailed content of How Can I Cross-Compile C Code from Linux to Windows Using GCC/G ?. For more information, please follow other related articles on the PHP Chinese website!