MinGW的优势

简介: MinGW的优势

之前的文章已经演示了 用 MinGW gcc 编译出 exe 文件,打印一个 hello。

但是 用 MSVC 一样能编译出 exe,打印一个 hello。那用 MinGW 的 gcc 意义何在。


点击 C:\MinGW\bin\mingw-get.exe ,勾选下面的 mingw32-pthreads-w32dev 安装包,安装到 MinGW。

安装完成之后,在 include 目录下就多了一个 pthread.h 头文件,如下:



在 C:\MinGW\projects 下面新建一个项目 zeus-pthread ,新建一个文件 zeus-pthread.c ,代码如下:

#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
static void * pthread(void *arg)
{
    printf("hello ffmpeg 1\n");
    return NULL;
}
int main(int agrc,char* argv[])
{
    pthread_t tidp;
    /* 创建线程pthread */
    if ((pthread_create(&tidp, NULL, pthread, NULL)) == -1)
    {
        printf("create error!\n");
        return 1;
    }
    /* 等待线程pthread释放 */
    if (pthread_join(tidp, NULL))
    {
        printf("thread is not exit...\n");
        return -2;
    }
    printf("hello ffmpeg 2\n");
    return 0;
}

执行以下命令开始编译:

cd C:\MinGW\bin
.\gcc.exe -g3 -c -o C:\MinGW\projects\zeus-pthread\zeus-pthread.o C:\MinGW\projects\zeus-pthread\zeus-pthread.c
.\gcc.exe -g3 -o C:\MinGW\projects\zeus-pthread\zeus-pthread.exe C:\MinGW\projects\zeus-pthread\zeus-pthread.o -lpthread

我们把 zeus-pthread.exe 移动到 C:\MinGW\bin 目录下,因为依赖一些 DLL。

这完全 跟 在 Linux 使用 gcc 跟多线程函数一样。

我们再用 Dependencies 查看一下 zeus-pthread.exe 的依赖库,如下:

只依赖于两个 dll。Windows 平台原本是没有 pthread_create 函数的。


不过 MinGW 没有 提供 fork 函数。如果需要更好的移植性,可以使用 cywin,cywin 有 fork 函数。

下面是 官网 介绍的 MinGW 的优势。


Headers, Libraries and Runtime

  • More than a million lines of headers are provided, not counting generated ones, and regularly expanded to track new Windows APIs.
  • Everything needed for linking and running your code on Windows.
  • Winpthreads, a pthreads library for C++11 threading support and simple integration with existing project.
  • Winstorecompat, a work-in-progress convenience library that eases conformance with the Windows Store.
  • Better-conforming and faster math support compared to VisualStudio's.

Tools

  • gendef: generate Visual Studio .def files from .dll files.
  • genidl: generate .idl files from .dll files.
  • widl: compile .idl files.
目录
相关文章
|
1月前
|
编译器 C语言 Windows
cryptopp使用Qt mingw编译,以及海思平台交叉编译
cryptopp使用Qt mingw编译,以及海思平台交叉编译
22 0
|
Ubuntu 编译器 芯片
FFmpeg开发笔记(十):ffmpeg在ubuntu上的交叉编译移植到海思HI35xx平台
FFmpeg开发笔记(十):ffmpeg在ubuntu上的交叉编译移植到海思HI35xx平台
FFmpeg开发笔记(十):ffmpeg在ubuntu上的交叉编译移植到海思HI35xx平台
|
1月前
|
编译器
使用海思v500交叉编译器编译qt5.4.2版本
使用海思v500交叉编译器编译qt5.4.2版本
13 1
|
1月前
|
编译器 Linux
boost库交叉编译ARM版本
boost库交叉编译ARM版本
37 2
|
2月前
|
物联网 编译器 测试技术
【嵌入式 交叉编译器】如何在 ARM 架构下选择和使用高版本交叉编译器
【嵌入式 交叉编译器】如何在 ARM 架构下选择和使用高版本交叉编译器
264 7
|
2月前
|
Linux C语言 开发者
Linux嵌入式系统之交叉编译中构建交叉编译工具链
Linux嵌入式系统之交叉编译中构建交叉编译工具链
19 0
|
5月前
交叉编译libvisca库ARM版本
交叉编译libvisca库ARM版本
39 0
|
7月前
|
Ubuntu
百度搜索:蓝易云【ubuntu 20.04 aarch64 平台交叉编译 glib教程!】
现在,你已经完成了在Ubuntu 20.04 aarch64平台上交叉编译glib的过程。你可以使用aarch64平台的交叉编译工具链来编译和构建适用于该平台的应用程序。记得参考glib的文档和相关资源,以获取更多关于配置和使用的详细信息。
119 1
|
存储 Shell
编译移植龙芯2K1000平台下的qt-5.13
本文记录对龙芯2K进行qt5.13.1版本的移植。 本文中对于tslib的安装不做讲解,使用了QT4进行核心板开发的童鞋一般情况下,应该已经安装好了tslib了,直接使用就行。
418 0
|
Ubuntu Linux 编译器
iperf-2.0.9 在 Linux下的编译 与 海思(arm)平台的交叉编译
iperf-2.0.9 在 Linux下的编译 与 海思(arm)平台的交叉编译
463 0
iperf-2.0.9 在 Linux下的编译 与 海思(arm)平台的交叉编译