PDA

View Full Version : Linking to .dylib from xcode




monkeyman23555
Feb 16, 2008, 11:33 AM
Hi

Well I am starting to program my ray tracer in xcode and I need to use pngwriter: http://pngwriter.sourceforge.net/
for simple image output.

I managed to get libpng work fine, by adding to my project the png.h file and the libpng.dylib from x11 to my project.

When I add both pngwriter.h and pngwriter.cpp to my project it starts to throw errors about linking and symbols not being found.

"_png_write_info", referenced from:
pngwriter::close() in pngwriter.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

When I include png.h in my main file without pngwriter being compiled then it builds fine.

Does anyone know what is going on?



kainjow
Feb 16, 2008, 10:16 PM
When I include png.h in my main file without pngwriter being compiled then it builds fine.

Does anyone know what is going on?

If you're including png.h and it's building without errors, what's the problem?

monkeyman23555
Feb 17, 2008, 05:57 AM
Well when I do this:

#include "png.h"

int main( int argc, char* const argv[] )
{
png_color_16 mybackground;
}


In my main file, then it does not give me an error, just warning that I did not use mybackground obviously. When I however include "pngwriter.cpp" in my build it gives me 29 errors of symbols not found.

kainjow
Feb 17, 2008, 08:45 AM
Probably because pngwriter.h doesn't include everything that is needed, but png.h does which is why it works. Generally with libraries like this you don't include a specific header, you include the main generic header, which appears to be png.h in this case.

monkeyman23555
Feb 17, 2008, 11:25 AM
Well pngwriter.h/.cpp worked with me in netbeans...

For the errors that I get when I do include it are all about png:
"_png_get_rowbytes", referenced from:
pngwriter::read_png_image(__sFILE*, png_struct_def*, png_info_struct*, unsigned char***, unsigned long*, unsigned long*)in pngwriter.o
pngwriter::readfromfile(char*) in pngwriter.o
"_png_set_expand", referenced from:
pngwriter::readfromfile(char*) in pngwriter.o
pngwriter::readfromfile(char*) in pngwriter.o
"_png_write_end", referenced from:
pngwriter::close() in pngwriter.o
"_png_set_gAMA", referenced from:
pngwriter::close() in pngwriter.o


Those are 4 of the errors. pngwriter.h does include "png.h" however.

Thats why I think it does not get the library in of libpng...
EDIT: Pngwriter is based on libpng, its not the same project...

monkeyman23555
Feb 18, 2008, 03:49 PM
Well I went looking in the pngwriter.cpp and searched for one of the errors in pngwriter::close().

Now the error is:
"_png_write_end", referenced from:
pngwriter::close() in pngwriter.o


but in the cpp "png_write_end" is called. How come it puts a "_" infront of the call???

monkeyman23555
Feb 18, 2008, 04:22 PM
Sorry for posting twice up there...

In the project settings under linking I made the Mach-O type to relocatable object. When I go to the settings of the dylib it is also Mach-O type...

I am not sure why it solved my problem, but if someone could tell me I'd be grateful...

Anyways thanks for the help...

EDIT: Now I am having the problem, when I compile and try to run it, it says there is no executable in the build directory...

MrEeeeez
Apr 5, 2009, 07:55 PM
Monkeyman, did you ever solve this problem? I'm running into the exact same situation.

monkeyman23555
Apr 6, 2009, 06:40 AM
No I never actually did find a solution to this problem, I ended up just using the built in library, Core Image...

but that makes it not cross platform which is not to my taste...

autorelease
Apr 6, 2009, 12:58 PM
http://forums.macrumors.com/archive/index.php/t-609963.html might be of some help. I've done it before by packaging the dylib in a framework, but I can't remember the URL of the tool I used for that.

Linking to a static library would be easier, but it would be less cross-platform.