与 Visual Studio 2010 的静态 libpng 链接

与 Visual Studio 2010 的静态 libpng 链接

问题描述:

我正在尝试向我的应用程序添加 PNG 支持,因此我想包含 libpng.我知道它需要 zlib,因此我也下载了它.我进入了 png 文件夹/项目/vstudio,然后打开了解决方案.我编译了它,它运行得很好.我将其中的一些标题添加到我的应用程序中,并复制了 lib 文件.我的程序是一个用 C++ 编写的 dll,后来在 C# 中使用.当我在 C# 中运行它时,它抱怨找不到我的 dll(如果我删除 png 部分,它会很好地工作).我以前遇到过这个问题,这通常意味着 dll 依赖项是错误的.
现在... libpng 编译了一些 .lib 文件和一些 .dll 文件.dll文件更大.我唯一的猜测是它也需要 dll 文件,但我已经看到人们可以在没有 dll 的情况下链接到 libpng.
所以我的问题是:如何将 libpng(和 zlib 用于该实例)编译为静态库,以及如何将它们包含在我的项目中?我在互联网上搜索过,但找不到任何有用的东西.

I'm trying to add PNG support to my application and thus I want to include libpng. I know it needs zlib and thus I downloaded that as well. I went into the png folder/projects/vstudio and I opened the solution. I compiled it and it went just fine. I added some headers from it into my application and I copied the lib files. My program is a dll written in c++ which is later used from C#. When I run it in C# it complains about not finding my dll (tough if I remove the png part it works fine). I've had this problem before and it usually means a dll dependency is wrong.
Now... libpng compiled both some .lib files and some .dll files. The dll files are bigger. My only guess is that it needs the dll files as well but I've seen that people can link to libpng without a dll.
So my questions is: How can I compile libpng(and zlib for that instance) into just static libraries and how can I include those in my projects? I've searched around the internet and I couldn't find anything useful.

要使所有库静态化,您必须从头开始"重新编译所有库为静态库.

To make all your libraries static, you would have to recompile everything "from scratch" as static libraries.

这只是意味着您应该为序列中的每个库创建一组项目,并将输出类型设置为静态库.

This simply means you should create a set of projects for each library you have in your sequence and set the output type to static library.

之后你应该消除库本身之间的库依赖(这意味着你应该将一些项目的输出链接到另一个项目,例如如果你的libpng"库使用libzip",这意味着你应该首先编译libzip"并将该输出(静态库)链接到您的libpng"项目.

After that you should eliminate library dependencies between the libraries themselves (this means you should link the output of some projects to another projects, e.g. if your "libpng" library uses "libzip", it means you should first compile the "libzip" and link that output (static library) to your "libpng" project.

最后,您将拥有为您的平台编译的大量静态库,您可以在您的项目中使用它们.

In the very end you would have a big set of static libraries compiled for your platform, which you can use in your projects.

还要提一下,尝试更仔细地使用谷歌搜索.我确定有人已经这样做了,您可能需要为您的平台下载一个 .lib 文件包(我知道很多时候"dev" 库包只包含一个导入库和相应的 .dll 文件,但是像你这样的爱好者有很多:)

Also to mention, try googling more carefully. I'm sure someone has this done and you would probably need to download a package of .lib files for your platform (I know that very often the "dev" bundle of libraries only includes an import library paired with appropriate .dll file, but there are a lot of enthusiasts like you :)