简体   繁体   English

使用MinGW进行C ++的DLL管理?

[英]DLL management for C++ with MinGW?

I recently decided to take a look at 2D graphics with C++, using MinGW on Windows 7. 我最近决定在Windows 7上使用MinGW来研究C ++的2D图形。

Since I was only going to need 2D graphics any library would be viable more or less (OpenGL, SDL, etc..). 因为我只需要2D图形,所以任何库都或多或少是可行的(OpenGL,SDL等)。 I decided to take a quick look at a few and check how easy they'd be to get working on windows with MinGW. 我决定快速浏览一下,并检查一下使用MinGW在Windows上进行工作的难易程度。

I soon noticed every library I tested (which were Cairo, SDL and GTK+) required tons of dll files in order to work. 我很快注意到我测试的每个库(开罗,SDL和GTK +)都需要大量的dll文件才能正常工作。 After compiling even a simple program from something like a tutorial it would give me like 5 or 6 different dll errors, forcing me to copy all of them into my program's working directory for it to even run. 从教程之类的程序甚至编译一个简单的程序后,它都会给我5到6个不同的dll错误,这迫使我将所有错误都复制到程序的工作目录中甚至可以运行。

Of course my program worked, but it's very cubersome to have this many DLLs just for a simple program. 当然,我的程序可以工作,但是对于一个简单的程序而言,拥有这么多的DLL确实很麻烦。 Making the program run on someone else's computer would require to ship all those DLLs along with it as seperate files, plus other DLLs that I got globally installed but others don't. 要使程序在其他人的计算机上运行,​​需要将所有这些DLL与它一起作为单独的文件以及我在全球安装的其他DLL一起提供。

It just seems so weird that something as popular as C++ would be so annoying to use because of all the DLLs required... Am I doing anything wrong? 似乎太奇怪了,因为所有必需的DLL都使像C ++这样流行的东西令人讨厌使用...我做错什么了吗? Could there be some magical solution to this problem? 可以为这个问题提供一些神奇的解决方案吗? Some tool to minimize or even completely eliminate these complications? 有一些工具可以最小化甚至完全消除这些并发症? It'd be cool to have to use fewer DLLs for my application. 必须为我的应用程序使用更少的DLL是很酷的。 Of course I won't be able to omit DLLs completely, but at least reducing the amount to a single one (one library = one DLL) or having the possibility to organize them in a subfolder of their own would be awesome. 当然,我将无法完全省略DLL,但是至少将其减少为一个(一个库=一个DLL),或者有可能将它们组织在其自己的子文件夹中会很棒。

Of course my program worked, but it's very cubersome to have this many DLLs just for a simple program. 当然,我的程序可以工作,但是对于一个简单的程序而言,拥有这么多的DLL确实很麻烦。 Making the program run on someone else's computer would require to ship all those DLLs along with it as seperate files, plus other DLLs that I got globally installed but others don't. 要使程序在其他人的计算机上运行,​​需要将所有这些DLL与它一起作为单独的文件以及我在全球安装的其他DLL一起提供。

If you're making an installer for your program, the installer should take care of installing the DLLs right alongside your program. 如果您要为程序制作安装程序,则安装程序应注意在程序旁边安装DLL。 It's pretty common practice, and won't be inconvenient for your user at all. 这是很常见的做法,完全不会给您的用户带来不便。 If you're just distributing a zip file with your app in it, just keep the DLLs in the folder you're zipping up (also a pretty common practice). 如果您只是在分发包含应用程序的zip文件,只需将DLLs保留在要压缩的文件夹中(这也是一种很常见的做法)。

It's also worth noting that you'll already have to send DLLs with your app. 还值得注意的是,您已经必须通过应用程序发送DLL。 GCC apps need libgcc_s_sjlj-1.dll and libstdc++-6.dll . GCC应用需要libgcc_s_sjlj-1.dlllibstdc++-6.dll MSVC apps, if I recall correctly, rely on the Visual C++ runtime library. 如果我没记错的话,MSVC应用程序依赖于Visual C ++运行时库。 A few more graphics libraries aren't likely to bother the user at all. 还有一些图形库根本不会打扰用户。

Am I doing anything wrong? 我做错什么了吗?

Nope, this seems like business as usual to me. 不,这对我来说像往常一样。 I recommend you continue your project without worrying too much about the DLLs. 我建议您继续进行项目,而不必过多担心DLL。

Could there be some magical solution to this problem? 可以为这个问题提供一些神奇的解决方案吗? Some tool to minimize or even completely eliminate these complications? 有一些工具可以最小化甚至完全消除这些并发症?

You could look into a DLL/EXE packer . 可以查看DLL / EXE包装器 It's highly unrecommended, though, because antiviruses tend to not appreciate the modified EXEs. 但是,由于防病毒软件往往不喜欢修改后的EXE,因此非常不建议这样做。 (A lot of malware uses packing techniques, so antiviruses are often suspicious of such packed apps by default.) (许多恶意软件都使用打包技术,因此默认情况下,防病毒软件通常会怀疑此类打包的应用程序。)

at least reducing the amount to a single one (one library = one DLL) 至少将数量减少到一个(一个库=一个DLL)

Technically you might be able to, but you'd probably need to rewrite the graphics library in question since right now it's set up for multiple DLLs. 从技术上讲,您也许可以,但是您可能需要重写有问题的图形库,因为现在它已针对多个DLL进行了设置。 I really don't recommend this either; 我也不推荐这样做。 the DLLs are separate because they're meant to be. DLL是分开的,因为它们本来就是这样。 They offer different functionality (for example, a quick glance at GTK+'s changelog showed mentions of libraries for SVG, JPG, and other file formats, as well as a lot of backend stuff to interface with the host OS, printers, etc.) so they're encapsulated into different libraries. 它们提供了不同的功能(例如,快速浏览GTK +的变更日志,其中提到了SVG,JPG和其他文件格式的库,以及用于与主机OS,打印机等交互的许多后端内容),因此它们被封装到不同的库中。 In some cases (libjpeg) these "sub-libraries" are even written by a different group, and the graphics library you're using just calls certain functions from the "sub-library". 在某些情况下(libjpeg),这些“子库”甚至是由不同的组编写的,并且您使用的图形库仅从“子库”中调用某些函数。

If you're really that insistent on having just one DLL, I think you're better off looking for some little, minimal-functionality library. 如果您确实坚持只拥有一个DLL,那么我认为您最好寻找一些小的,功能最少的库。 Since you just want 2D graphics you might be able to get away with that. 由于您只想要2D图形,您也许可以摆脱它。

or having the possibility to organize them in a subfolder of their own would be awesome 或有可能将它们组织在自己的子文件夹中会很棒

Unfortunately you can't do this. 不幸的是你不能这样做。

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

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