views:

430

answers:

1

Hey guys. 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.

+3  A: 

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.

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.


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 :)

Kotti
Really recompiling this stuff is not that hard - create a project, add all files. And no more issues with different runtime versions or anything like that.
sharptooth
Well, try fully building `gtkmm` by "creating project and adding files" ;) *Sometimes all those inner dependencies can be a real pain in the ass.*
Kotti
Maybe, but we build zlib and SQLite without any hassle.
sharptooth
Yeah it was actually very simple. One more question: If I want to add libjpg too which also depends on zlib how should I make the linking? Let both libpng and libjpg to statically link zlib in them and then link my application to both?
Sanctus2099
@Sanctus2099: No, you compile each separately and link them to the final project. Or you can put all the three libraries sources into one project and get a single static library. The first approach would be more flexible, but require more configuration.
sharptooth