Cross compiling under Linux to generate windows program

biigpanda 2022-08-06 16:24:52 阅读数:291

crosscompilinglinuxgeneratewindows

The Linux environment uses Ubuntu. The principle is to use mingw32 to cross-compile windows programs to run under windows.

The specific steps are as follows:

First, install mingw32

1. Modify sources.list

sudo vim /etc/apt/sources.list

Add a new line at the bottom of the file:

deb http://us.archive.ubuntu.com/ubuntu trusty main universe

2, update packages

sudo apt update

3. Install mingw32

sudo apt-get install mingw32

4. Verify the installation results

I installed i586-mingw32msvc-gcc here, some people installed i486-mingw32-gcc, I don't know what compiler is installed, you can use the find command to search for the keyword mingw32, or you can directly enter i and then tab, but there will be more results.

i586-mingw32msvc-gcc -vUse built-in specs.Target: i586-mingw32msvcConfigured as: /build/buildd/mingw32-4.2.1.dfsg/build_dir/src/gcc-4.2.1-2-dfsg/configure -v --prefix=/usr --target=i586-mingw32msvc --enable-languages=c,c++ --enable-threads --enable-sjlj-exceptions --disable-multilib --enable-version-specific-runtime-libsThreading model: win32gcc version 4.2.1-sjlj (mingw32-2)

Installation succeeded

Second, compile windows program

New code test.c:

#include int main(){printf("windows application\n");// Judging by the _WIN32 macro, so that it can also be compiled and passed under Linux#ifdef _WIN32system("pause");#endifreturn 0;}

Compile:

i586-mingw32msvc-gcc test.c

The a.exe program that can be run under Windows will be generated.

copyright:author[biigpanda],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/218/202208061617043161.html