MinGW-W64 介绍 应用. 扩展: build 编译 compile 生成 CMake makefile gcc dll lib V1.0
作者:互联网
MinGW
有两个名字相近的项目,MinGW与MinGW-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"页面含:
-
文件夹目录——源码、第三方工具、细化组织的工具包、截图等文件夹;
-
页面的正文含发布(release)的工具包。
建议从正文获取发布的工具包(其链接指向深层的文件夹目录)。正文中发布的工具包有在线安装器与各种的版本工具包的下载链接。
在线安装器带个界面,没有版本细化说明,容易断线失败,建议使用下载链接。 -
在线安装器:
版本
当前工具包版本为"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位操作系统。
线程特性、调试特性
版本
当前为了兼容性,选择了i686-win32-sjlj,对应的文件目录路径为Toolchains targetting Win32。
扩展参考:
- linux - How do I compile and link a 32-bit Windows executable using mingw-w64 - Stack Overflow
- MinGW:sjlj,warf,seh各版本的区别以及下载地址_百口可乐__的博客-CSDN博客_mingw seh
安装配置
解压即可。
建议添加解压路径到环境变量PATH
。以便cmd等系统shell,以及如Luarocks等工具从任意路径可访问到。
其中bin文件夹下有多个单文件编译器(GCC),每个编译器对应不同的配置,描述于文件名(mingw-w32-xxx-gcc.exe)中。
可以复制或链接所需配置的编译器,命名为"mingw32-gcc.exe"。
如Luarocks限定使用此名称。
(VS中通过如"vcvars32.bat"进行以上配置)
类似"ming32-gcc",可以复制或链接mingw32-make
,命名为make
。
主要功能
gcc
:build的核心操作。通常无需手动调用,而是由所需编译项目的makefile脚本自动调用。见扩展参考。gendef
、dlltool
:进行.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.exe
:
- 选择项目源(source code)
- Configure扫描系统环境(如mingw-gcc、所需头文件)
- 解析出项目编译选项供选择
- 生成(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.
-
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.dll
、dlltool -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。
- 用到的命令
gendef
、dlltool
。 .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 launched (runtime)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编译
-
LuaBinaries - Windows Libraries/Static at SourceForge.net
In Windows, packages are associated with a compiler, because usually the library files are not compatible between compilers.
DLL packages contain dynamic libraries (.dll), import libraries (.lib), and include files (.h). So they contain run time and development (build time) files together in the same package.
此处使用MinGW-gcc,故,Luarocks中使用的LuaLib需为lua-5.3.6_Win32_mingw6_lib.zip。
参考库转换。
标签:gcc,CMake,lib,Windows,w64,MinGW,64,build 来源: https://www.cnblogs.com/RobertL/p/16345831.html