简体   繁体   English

MinGW / MinGW64链接和对msvcrt.dll的依赖

[英]MinGW / MinGW64 Linking and Dependency on `msvcrt.dll`

I am coding for WinAPI in MinGW 我在MinGW中为WinAPI编码

One thing I still have not fully understood is the VC redistributable, I got a whole pack of question to it 我仍然不完全了解的一件事是VC可再发行,我对此提出了一整套问题

Some say that such programs will need the msvcrt.dll 有人说这样的程序将需要msvcrt.dll

  1. is the same library needed for bot c++ and c compilation? bot c ++和c编译需要相同的库吗?
  2. is this available on all targets of clients? 这对客户的所有目标都可用吗?
  3. must I redistribute it? 我必须重新分发吗? can I redistribute it? 我可以重新分发吗?
  4. can I easily get rid of this external dependency? 我可以轻松摆脱这种外部依赖吗?
  5. is there other compiler that will allow me not to carry such unpleasant external dependency? 是否有其他编译器可以让我不要携带这种令人不快的外部依赖关系? (as I vaguely remember hearing that something is wrong with it - it is probably not core system lib, I heard, or it is not free to use and redistribute the library) (正如我模糊地记得听到的声音有问题-我听说它可能不是核心系统库,或者不是免费使用和重新分发该库)

I see something wrong is here as I would like to produce no dependency small exes only calling the system WinAPI and if I use some like C standard library functions functions I would prefer it economically and statically compiled in, not any third-party dependencies 我看到这里有问题,因为我不希望产生仅依赖于系统WinAPI的小依赖项,如果我使用C标准库函数之类的函数,我希望将其经济且静态地编译进去,而不希望任何第三方依赖项

  1. MSVCRT.DLL contains mostly the C runtime, and MinGW can only use the C part. MSVCRT.DLL主要包含C运行时,而MinGW只能使用C部分。 C++ binary code cannot be used across compilers generally. C ++二进制代码通常不能跨编译器使用。
  2. It depends on your "target". 这取决于您的“目标”。 It is available from Windows 2000. 它可以从Windows 2000获得。
  3. No. No. It is Microsoft-proprietary code, and every Windows version has a slightly different version. 不会。这是Microsoft专有的代码,每个Windows版本的版本都略有不同。
  4. No. I am not aware of a mature alternative C run-time DLL. 不,我不知道成熟的替代C运行时DLL。
  5. You do not need to worry about the dependency, as it is available everywhere. 您不必担心依赖项,因为它随处可见。 (Do notice that it is not really a great run-time, esp. regarding multi-byte characters.) (请注意,这并不是一个很好的运行时,尤其是关于多字节字符的运行时。)

Microsoft compilers can link with "static" libraries so that the resulting executable depends only on system DLLs like kernel32.dll, user32.dll, etc. MinGW cannot do this (yet). Microsoft编译器可以与“静态”库链接,因此生成的可执行文件仅取决于系统DLL,例如kernel32.dll,user32.dll等。MinGW无法做到这一点(至今)。

EDIT: A concise description of the MSVCRT.DLL problem is here . 编辑:MSVCRT.DLL问题的简要描述在这里

According to the MS White-paper here: 根据MS白皮书:

http://www.microsoft.com/en-gb/download/details.aspx?id=13350 http://www.microsoft.com/zh-CN/download/details.aspx?id=13350

you can redistribute certain parts of the Visual Studio components. 您可以重新分发Visual Studio组件的某些部分。

Some software, such as the Microsoft .NET Framework, can be distributed. 可以分发某些软件,例如Microsoft .NET Framework。 Components of software products included in MSDN subscriptions that can be distributed (either within an application or as separate files) without royalty are identified in the REDIST.TXT file associated with the product. 与产品相关联的REDIST.TXT文件中标识了MSDN订阅中包含的,可以分发(在应用程序中或作为单独的文件)而没有使用费的软件产品组件。 Components that can be distributed to non-Microsoft platforms are identified in the OTHER-DIST.TXT file associated with the product. 与该产品关联的OTHER-DIST.TXT文件中标识了可以分发到非Microsoft平台的组件。 Code identified as distributable that has the extension .lib cannot be directly distributed; 具有扩展名.lib的被标识为可分发的代码不能直接分发; it must be linked into the application. 它必须链接到应用程序。 However, the resulting output can be distributed. 但是,可以分配结果输出。

You may also: 您还可以:

  • Modify and distribute source code and objects for code marked as “sample” or “Code Snippet”. 修改和分发标记为“样本”或“代码段”的代码的源代码和对象。
  • Distribute the unmodified output of Microsoft Merge Modules for use with an application's .msi file. 分发Microsoft合并模块的未修改输出,以与应用程序的.msi文件一起使用。
  • Distribute the MDAC_TYP.EXE file containing core data access components (such as the Microsoft SQL Server OLE DB provider and ODBC driver). 分发包含核心数据访问组件(例如Microsoft SQL Server OLE DB提供程序和ODBC驱动程序)的MDAC_TYP.EXE文件。
  • Distribute the object version of C++ libraries (Microsoft Foundation Classes, Active Template Libraries, and C runtimes). 分发对象版本的C ++库(Microsoft基础类,活动模板库和C运行时)。

MS also produces a redistributable package specifically for the purpose of developers: http://www.microsoft.com/en-gb/download/details.aspx?id=40784 MS还专门为开发人员提供了可重新分发的程序包: http : //www.microsoft.com/en-gb/download/details.aspx?id=40784

So, to answer your questions: 因此,回答您的问题:

  1. Yes. 是。 Although it is "purely C", it contains fundamental functions that are used by the C++ part of C as well, such as file I/O, time and date functions, math functions, and so on. 尽管它是“纯C”,但它也包含C的C ++部分使用的基本函数,例如文件I / O,时间和日期函数,数学函数等。
  2. Within reason. 在合理范围内。 See link above. 请参阅上面的链接。
  3. No, yes. 不,是的 As described above: You may choose to just say to customers "you need to download an install this package", but the license should allow you to distribute it free of charge with your product. 如上所述:您可以选择仅对客户说“您需要下载安装此软件包”,但是许可证应允许您随产品免费分发。
  4. Depends on what you call "easily" and exactly what parts of the library your code uses. 取决于您所谓的“轻松”内容以及代码所使用的库的确切部分。 Some functions may be easy to replace, others not so - but it's not easy in the sense of "yes, just go do http://www.example.com/msvcrt.dll-plugin-replacement " - it would require coming up with some replacement code. 有些功能可能很容易替换,而有些则不是-但就“是的,只是去http://www.example.com/msvcrt.dll-plugin-replacement ”的意义上说,这并不容易-这需要启动与一些替换代码。 The reason MinGW DOESN'T come with its own C library is that it's not entirely trivial to write a replacement for ALL of the windows functionality that you may need here... MinGW不提供自己的C库的原因是,编写此处可能需要的所有Windows功能的替代品并不是一件容易的事...
  5. See above - if it was easy, someone would have done it. 见上文-如果这很容易,那么有人会做到的。 There MAY be some compilers out there that come with their own library, but it's probably not a free-of-charge and free to distribute one (I'm not aware of any product that doesn't rely on the MSVCRT.DLL - but it's not impossible that one exists) 可能有一些编译器带有它们自己的库,但是它可能不是免费的并且免费分发(我不知道有没有不依赖MSVCRT.DLL的产品。这不是不可能的存在)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM