views:

105

answers:

1

Hi,

I installed from kubuntu's package management this handy pnglite library. It contains just one header file "pnglite.h" and one object file "pnglite.o". I have found out where those files are, but I don't know how to link them. I'm using netbeans, but don't know how to link them in there. Also I don't understand how to link them at console.

I have a little test program that I would like to test, but I get the error message "undefined reference to function: XXXXXXX". Both netbeans and at console I'm using gcc. That header file is in /usr/include directory, object file is in /usr/lib directory and my test program is under my programming directory at my home directory.

Should I put that header and object into the same directory as where my source is? Or is there a way to link them from their current locations? I know that it should be possible to link them from where they are at the moment and I would like to know and understand how to do that.

Any help will be appreciated :)

+2  A: 

You just need to add /usr/lib/pnglite.o to your linking invocation of gcc, plus any shared libraries that pnglite requires (from your comment it appears to require zlib). Eg if your source is in myapp1.c and myapp2.c, then:

gcc -c myapp1.c
gcc -c myapp2.c
gcc -o myapp myapp1.o myapp2.o /usr/lib/pnglite.o -lz
caf
Thanks for the answer. I guess that would do it in common case. I tried that, but now I get many error messages referring to that pnglite.o saying "undefined reference to 'crc32' ". No idea what that's about.
zaplec
Your linker fails because either your app or pnglite.o uses a resource crc32 that is not in the compiled object files or a shared library.. have you used the same shared libraries as when you builded without pnglib?
Erik
@zaplec: The pnglite object appears to need to be linked against some shared libraries - for example `crc32` is in zlib, so you add `-lz` to the link line too (I have updated the answer).
caf
Thanks caf. Now it's working and it's my mistake that I didn't read carefully enough that documentation of pnglite as it is said there that pnglite uses zlib.
zaplec