I'm at my wit's end trying to get this to work. I've been struggling for hours on end with CMake trying (and retrying) to do the following:
(1) compile zlib as static
(2) compile libpng as static with the static zlib I just got
(3) use this conglomerated library in an executable program
The result of this is always some variation of:
or sometimes without the prefixes:
undefined reference to `inflateEnd'
I know these functions are from zlib. Linking the executable with the static zlib does not help, no matter what order the libraries are in.
If it matters any, I was able to statically compile/link Allegro 4.4.2, but I can't get these specific libraries to cooperate.
What am I doing wrong? I would appreciate step-by-step instructions (if it's necessary).
I don't understand what you're trying to do here. You shouldn't link one static library to another. You should build both independantly (you'll need zlib headers to compile libpng though) and then link both libraries to your program.
edit: if those errors are actually from your program build, make sure libpng is linked ahead in order of zlib.
Well I was trying to compile both into one library, so that isn't possible? OK, kinda makes sense.
I'm still linking to both libraries for the EXE, and it's still giving me those undefined reference errors (even did a full rebuild).
Going to delete all related the headers and lib files I have and try this once more from scratch...
Did you link them in the right order?
I tried both ways last time.
This time, when compiling libpng the shared version of the library stops on undefined reference errors similar to what is found in the executable. Do I have to specify the dynamic version of zlib in the configure script (using CMake)?
Where does cmake come into play here? Are you building the library with examples (which have 'main' functions) built into them? What are you using to build libpng, its own build system or your own? Paste the complete output of the build here please.
edit: if it's the libpng examples/tests failing then your zlib isn't built right. It doesn't matter if it's static or dynamic.
I've been using CMake to configure, both zlib and libpng. I'm compiling with mingw32-make.
I've re-ran the zlib build with shared lib built (now I have both). Output:
Do those warnings mean the library is incorrectly built?
Here's libpng compile process:
Is this a developement version of libpng? Its failing to compile its own tests. In any case, they both seem to have built correctly. The only thing to do is try using them and see if they work.
So far, nothing. I tried using these two compiles and I STILL get undefined's.
I might have the wrong ZIP of the source code, is the only conclusion I can reasonably come to.
I'll edit back in here if I get it to work off of a different source version/zip/whatever. It'll be a while before I can try though, I have other things to do now ("maintenance" on a new laptop).
EDIT: Yep, that was the source of all this mess, I was using the wrong zlib source code distribution. Problem SOLVED.
Thank you, Trent, for the help.
To build zlib you can use win32/makefile.gcc or else you need MSYS. I don't know why you're trying to use cmake to build zlib, because it doesn't come with CMakeLists.txt unless that's a recent addition.
With MinGW
cd zlib copy win32\makefile.gcc .\makefile.gcc mingw32-make -fmakefile.gcc mingw32-make install prefix=c:\mingw -fmakefile.gcc
With MSYS
cd zlib ./configure mingw32-make mingw32-make install prefix=/c/mingw
To build libpng, it's pretty much the same except you can use a custom makefile, MSYS, or Cmake.
MinGW
cd png copy scripts\makefile.mingw .\makefile.mingw mingw32-make -fmakefile.mingw mingw32-make install -fmakefile.mingw
MSYS
cd png ./configure --prefix=/c/mingw mingw32-make mingw32-make install
Cmake
cd png mkdir build cd build cmake -G "MinGW Makefiles" .. mingw32-make mingw32-make install
When building with MinGW or MSYS by themselves, you should get both the static and dynamic libraries by default.
Edit
Too late to the party...