hello world"."/> hello world".">
Home > Article > Operation and Maintenance > Can the mingw compiled version run under linux?
Mingw compiled can run under Linux. The compilation method is: 1. Install mingw32 through the "sudo apt-get install mingw-w64" command; 2. Run "sudo apt-get install wine -development wine ~/hello.exe >hello world”.
The operating environment of this tutorial: ubuntu18.04 system, mingw32, Dell G3 computer.
Can the mingw compiled version run under linux?
able.
Linux platform cross-compile Windows program
Compilation test environment: ubuntu18.04
Step 1: Install mingw32
sudo apt-get install mingw-w64 sudo apt-get install mingw-w64-tools sudo apt-get install mingw-w64-i686-dev sudo apt-get install mingw-w64-x86-64-dev
The above may be repeated In order to save effort, we installed them directly.
After installation, you can compile the code
i686-w64-mingw32-gcc -o hello.exe hello.c
Part 2: Test the compiled program
The compiled exe file can be copied to Tested on windows, but to save effort, I want to run it directly on linux. This requires complete wine.
sudo apt-get install wine-development wine ~/hello.exe >hello world
Part 3: Compiling 64-bit programs
Because I need to compile x64-bit programs, but the test found that the program is a 32-bit program.
x86_64-w64-mingw32-gcc -o hello64.exe hello.c
Part 4: Using the pthread library on windows
pthread is really easy to use. Windows does not have the pthread library by default.
i686-w64-mingw32-gcc -o pthread_create.exe pthread_create.c -lpthread -D__WIN32
I actually found that it has been compiled directly, indicating that mingw32 has included the pthread library.
I ran to windows and executed it, and it reported "libwinpthread-1.dll.......... not found"
I directly copied /usr/i686-w64-mingw32/ Copy the libwinpthread-1.dll file in the lib folder to Windows. Found it works.
Simple enough and rough enough, right? But it’s really cool
In fact, I also downloaded the pthread library under Windows, but unfortunately it still reported that the library cannot be found. Maybe gcc is not implicitly loaded.
About the problem of missing libgcc_s_dw2-1.dll in the MinGW compiler
It turns out that dynamic linking is used by default when linking, and the other party’s computer has no dependencies DLL module.
So I added the command after the link:
-static-libstdc++ -static-libgcc
Related recommendations: "Linux Video Tutorial"
The above is the detailed content of Can the mingw compiled version run under linux?. For more information, please follow other related articles on the PHP Chinese website!