Home > Operation and Maintenance > Linux Operation and Maintenance > Can the mingw compiled version run under linux?

Can the mingw compiled version run under linux?

藏色散人
Release: 2023-03-24 11:00:01
Original
2182 people have browsed it

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”.

Can the mingw compiled version run under linux?

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template