ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

MinGW-W64 介绍 应用. 扩展: build 编译 compile 生成 CMake makefile gcc dll lib V1.0

2022-06-06 04:00:08  阅读:290  来源: 互联网

标签:gcc CMake lib Windows w64 MinGW 64 build


MinGW

有两个名字相近的项目MinGWMinGW-w64
MinGW经典,但貌似未维护,下面讨论使用MinGW-w64
项目名MinGW-w64中64非表示64位版,参考项目文件网站标题的"MinGW-w64 - for 32 and 64 bit Windows"。

项目介绍

MinGW: Windows上的运行环境包,以GCC编译器为核心,包括其运行环境(头文件、支持库),上下游工具链(Toolchains/Toolsets/binutils)。

有其他运行环境包,如Cygwin,以及基于MinGW的MSYS2
参考文末MinGW介绍摘要

下载

项目文件网站上的Download按钮为源码下载,Files标签子页面有编译完成的工具包(Toolchains)。
建议使用包。

"Files"页面含:

版本

当前工具包版本为"MinGW-W64 GCC-8.1.0"。
其中"MinGW-W64"为项目名,非表示仅有64位版,参见MinGW子版本节。
核心是"GCC"编译器,版本号为"8.1.0"。

区分"MinGW-W64"项目版本。
如路径Files/mingw-w64/mingw-w64-release下的项目文件打包"mingw-w64-v10.0.0.zip"。

子版本

正文中工具包版本下有不同配置组合的子版本
配置包含:系统架构、线程特性、调试特性。

系统架构

  • x86_64: 简称X64,64位操作系统
  • i686: 32位操作系统 (i386的子集)

面向单个目标(single-target)系统。
x86_64仅能生成64位二进制文件,不能生成32位二进制文件;i686仅能生成32位二进制文件。

不同系统架构工具包解压出来的文件夹名有区分:"mingw64"、"mingw32",对应64位、32位操作系统。

线程特性、调试特性

参见MingGW64 版本区别于各版本说明 - PCYO

版本

当前为了兼容性,选择了i686-win32-sjlj,对应的文件目录路径为Toolchains targetting Win32

扩展参考:

安装配置

解压即可。
建议添加解压路径到环境变量PATH。以便cmd等系统shell,以及如Luarocks等工具从任意路径可访问到。

其中bin文件夹下有多个单文件编译器(GCC),每个编译器对应不同的配置,描述于文件名(mingw-w32-xxx-gcc.exe)中。
可以复制或链接所需配置的编译器,命名为"mingw32-gcc.exe"。
Luarocks限定使用此名称。
(VS中通过如"vcvars32.bat"进行以上配置)

类似"ming32-gcc",可以复制或链接mingw32-make,命名为makemingw32-make

主要功能

  • gccbuild的核心操作。通常无需手动调用,而是由所需编译项目的makefile脚本自动调用。见扩展参考
  • gendefdlltool:进行.a.lib.dll互转。见参考节库转换
  • make:执行makefile脚本。通常已预先通过CMake配置好项目的编译选项以生成makefile。

提醒,功能与工具包的系统架构有关。如dlltool区分32位、64位。


扩展参考

编译

compile,是build中的核心环节。(此处使用GCC编译器)
源文件(如.c),编译得到目标文件.o,object file),链接各目标文件,得到输出文件(如.exe/.dll/.lib)。
可编译-链接分步进行;或集中链接-编译一步到位,统称为编译
有大量参数,通常由make按makefile配置(参考CMake)执行。

详见:gcc "undefined reference to" 问题解决方法_边界流浪者的博客-CSDN博客_gcc编译undefined reference to(编译过程)

build

构建、生成。开发环境相关的系统流程(build system/build tool),常见"configure, make, make install"。核心环节为编译
另参考CMake

CMake

build的可选环节。
Windows平台下,配置项目,生成makefile(CMake:Create Makefile?)。
CMake工具的官网

CMake-gui.exeCMake MinGW makefile

  1. 选择项目源(source code)
  2. Configure扫描系统环境(如mingw-gcc、所需头文件)
  3. 解析出项目编译选项供选择
  4. 生成(Generate)指定编译环境(如MinGW)下的makefile。
  • 非官网介绍PCRE \ NON-AUTOTOOLS-BUILD.txt \ Building PCRE2 on Windows with CMake

    CMake creates project files (make files, solution files, etc.) tailored to numerous development environments.

    Run cmake-gui from the Shell envirornment of your build tool, for example, Msys for Msys/MinGW or Visual Studio Command Prompt for VC/VC++.

    after configure - generate from CMake.

    The build directory should now contain a usable build system, be it a solution file for Visual Studio, makefiles for MinGW, etc.

    Exit from cmake-gui and use the generated build system with your compiler or IDE.

Install-MinGW.pdf

适用于MinGW项目(而非MinGW-W64项目),包含:

  • 在Installation Manager中添加组件/包(components/packages)。

  • MinGW Shell。来自上面步骤添加的MSYS组件,对应"msys.bat"

    This is an alternative shell for interacting with Windows computers in a terminal window. Using the MinGW shell (rather than cmd) has the benefit of providing Unix-like commands such as ls and more and so on, rather than the equivalent DOS commands.

MinGW介绍摘要

  • MinGW-w64(项目官网)

    Mingw-w64 is an advancement of the original mingw.org project, created to support the GCC compiler on Windows systems.

    Headers, Libraries and Runtime

    Everything needed for linking and running your code on Windows.

    Tools

  • Downloads - MinGW-w64(项目文件托管网站)

    The heart of the Mingw-w64 project is headers and support libraries to run the output of GCC on Windows.

    Since Mingw-w64 is neither the home of GCC nor of binutils, several sets of installation packages which combine them are available.

  • MinGW-w64 - for 32 and 64 bit Windows download | SourceForge.net

    The mingw-w64 project is a complete runtime environment for gcc to support binaries native to Windows 64-bit and 32-bit operating systems.

  • PCRE2 \ Win32 builds

    MinGW: A collection of freely available and freely distributable Windows specific header files and import libraries combined with GNU toolsets that allow one to produce native Windows programs that do not rely on any 3rd-party C runtime DLLs.

    Select the particular IDE / build tool that you are using (Visual Studio, MSYS makefiles, MinGW makefiles, etc.)

  • Installing a C++ Development Environment for MS-Windows (MinGW, MSYS, jGRASP) (jmu.edu)

    development environments for C/C++ programmers

MinGW Shell

MinGW应用程序的用户交互环境。(环境内能访问到MinGW\bin)
可以是cmd,也可以来自MSYS2中的"msys.bat"(配置cmd环境,参考Install-MinGW.pdf)。

库转换

gendef lua53.dlldlltool -d lua53.def -D lua53.dll -l lua53.lib -k会由lua53.dll生成lua53.lib。应用参见Luarocks

  • c - Link against a Windows .dll+.lib file combination with GCC under Cygwin? - Stack Overflow

    link against a .lib, then you can (indirectly) link against a DLL.

    In the MSVC world, it is not unusual to create an import library along with a DLL. It is a static library (.lib) that loads the DLL and wraps the interface of the DLL. You just call the wrapper functions in the (static) import library and let the import library do all the DLL-related things.

  • .dll、.lib、.a的转换_witton的博客-CSDN博客_.lib转.a

    • 可以由.dll经过中间文件.def生成.a/.lib
    • 可以由lib转dll。
    • 用到的命令gendefdlltool
    • .lib.a就是扩展名的关系。libabc.a-abc.lib
  • 如何将linux下的.a库转到windows下.lib库 | Firefly's space (wordpress.com)

    使用dlltool --help查看帮助。

  • c++ - What is the difference between .o, .a, and .so files? - Stack Overflow

    .a is an "archive". ..., in the context of the GNU toolchain, it is a library of object files (other toolchains especially on Windows use .lib for the same purpose, )

    .o is an object file. This is code that is compiled to machine code but not (typically) fully linked - it may have unresolved references to symbols defined in other object files (in a library or individually) generated by separate compilation.

    Object files contain meta-data to support linking with other modules, and optionally also for source-level symbolic debugging (in GDB for example).

    Other toolchains, again typically on Windows, use the extension .obj rather than .o.

    .so is a shared object library (or just shared library). This is dynamically linked to an executable when a program is launchedruntime)rather then statically linked at build time.

    It allows smaller executables, and a single object library instance to be used by multiple executables.

    Unlike .o or .a files, .so files used by an application must be available on the runtime system. Other systems (again typically Windows) use .dll (dynamic link library) for the same purpose.

Luarocks

LUA_LIBDIR配置的LIB会按lua.dll>lua.lib顺序尝试。(不包含.a
若使用lua.dll会导致"undefined reference"错误(准备开另一篇记录)。
而Lua源码LuaBinaries中提供的静态库仅包含.a(及头文件)。参考Lua编译
故需进行库转换

当Luarocks需要编译时会查找系统环境下的mingw-gcc

Lua编译

标签:gcc,CMake,lib,Windows,w64,MinGW,64,build
来源: https://www.cnblogs.com/RobertL/p/16345831.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有