Linking to .dylib from xcode

Discussion in 'Mac Programming' started by monkeyman23555, Feb 16, 2008.

  1. macrumors newbie

    Joined:
    Feb 16, 2008
    #1
    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?
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    If you're including png.h and it's building without errors, what's the problem?
     
  3. thread starter macrumors newbie

    Joined:
    Feb 16, 2008
    #3
    Well when I do this:


    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.
     
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    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.
     
  5. thread starter macrumors newbie

    Joined:
    Feb 16, 2008
    #5
    Well pngwriter.h/.cpp worked with me in netbeans...

    For the errors that I get when I do include it are all about png:
    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...
     
  6. thread starter macrumors newbie

    Joined:
    Feb 16, 2008
    #6
    Well I went looking in the pngwriter.cpp and searched for one of the errors in pngwriter::close().

    Now the error is:
    but in the cpp "png_write_end" is called. How come it puts a "_" infront of the call???
     
  7. thread starter macrumors newbie

    Joined:
    Feb 16, 2008
    #7
    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...
     
  8. macrumors newbie

    Joined:
    Apr 5, 2009
    #8
    Monkeyman, did you ever solve this problem? I'm running into the exact same situation.
     
  9. thread starter macrumors newbie

    Joined:
    Feb 16, 2008
    #9
    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...
     
  10. macrumors regular

    Joined:
    Oct 13, 2008
    Location:
    Achewood, CA
    #10

Share This Page