Using external C library in Mac app

Discussion in 'Mac Programming' started by monsieurpaul, Jan 7, 2011.

  1. monsieurpaul, Jan 7, 2011
    Last edited: Mar 11, 2011

    monsieurpaul macrumors regular

    Joined:
    Oct 8, 2009
    #1
    Hello all,

    Sorry for the long and messy post but I am juggling with concepts I don’t fully understand.

    My goal (self-imposed as a way to learn Objective-C/Cocoa) is to create a Mac app for creating QR Codes (the 2D barcodes). I don’t want that my app relies on another website (zxing or kaiwa for example) for doing all the work and I found a C library (libqrencode) that seems to fit the bill. Now come the questions…

    According to the documentation of this library I must build it using ./configure, make, make install. I understand this for a program but not so well for a library. What will be the result of the build? A .dylib file?

    When I try to build the library the official way, the compiler tell me that I need to have the library libpng installed. I understand that this library is replaced in Cocoa by another so it gives me 2 choices :
    - I install libpng and go on. Easier (or rather less difficult) but not very satisfying and I think my app using libpng would never makes it to the App Store (one can dream…)
    - I rewrite the part of the library using libpng (I found only 1 function using it). Much more difficult and much more satisfying.

    My first try (quick and dirty) was to include all the .c and .h files of the sources directly in my project. Is it feasible? Acceptable?

    And last but not least, is this legit? The library is licensed under the GNU Lesser General Public License. I understand that I can use it in a commercial software?

    I have tried first to google my way out of these questions but I have been overwhelmed by all the information I found…

    Thank you,

    Paul
     
  2. ulbador macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #2
    Depending on how it's built, you SHOULD get an .so file. You would then include this file in your library path, plus the relevant .h files in your compile path so you can compile.

    LGPL permits the use of the library within the commercial program, so you will be fine.
     
  3. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #3
    I would just install qrencode via MacPorts. This is will give you libqrencode compiled as a .dylib in /opt/local/lib and the header files in /opt/local/include.

    You'd just need to add /opt/local/lib to the library search path and /opt/local/include to the header search path in your Xcode project, as well as link to libqrencode.

    I have app's from the app store that utilise external 3rd-party libraries. Apple wouldn't object to this (I don't think they object to this even on the iPhone/iPad). You'd just need to include the .dylib file in your application bundle.
     
  4. monsieurpaul thread starter macrumors regular

    Joined:
    Oct 8, 2009
  5. monsieurpaul thread starter macrumors regular

    Joined:
    Oct 8, 2009
    #5
    Hello,

    I am reactivating this thread because of a new problem. After recompiling the library (libqrencode), adding the dylib in the project files and the search paths in the project settings, I am able to use the library in my app.
    However, when I install the application on another Mac, it crashes with the message that it can't find the external dylib.
    That makes sense, but how can I add a copy of this library in my application so that it can works on whatever Mac I install it ?

    thanks,

    Paul
     
  6. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #6
    Embedding a Private Framework in Your Application Bundle

    http://developer.apple.com/library/...orks.html#//apple_ref/doc/uid/20002258-106880


    Also see the dyld man page, especially the @executable_path, @loader_path, and @rpath prefixes:
    http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/dyld.1.html

    You will also need to use 'otool' to inspect and/or change the path by which your embedded dylib is loaded. There's a link to otool's man page at the bottom of the dyld man page.
     
  7. monsieurpaul thread starter macrumors regular

    Joined:
    Oct 8, 2009
    #7
    Thanks for the links. Since my post, I found an interesting tutorial here.
     

Share This Page