Thread: linking to libraries

  1. #1
    Registered User
    Join Date
    Sep 2008

    linking to libraries

    This is my first real project with C so bare with me.

    I am trying to write a program that will be able to, among other things, read the geo tags of a tiff using the libgeotiff library. I downloaded and installed the library, and its dependent, libtiff, from source.
    How do I include these now into my program? If I do an #include "absolute path", I can get the .h file, and use the type definitions, but when I call any of the functions, I get a symbol(s) not found error.

    I am using Xcode on mac os x.

    Thank you

  2. #2
    Registered User ssharish2005's Avatar
    Join Date
    Sep 2005
    Cambridge, UK
    What compile are using?? If you’re on gcc then you could -l flag to link the libraries or perhaps you also specify the library path explicitly. The following are the few examples

    Explicitly specifying
    gcc -o myCode -Wall myCode.c  /usr/lib/libm.a
    using -l flag
    gcc -o myCode -Wall myCode.c  -lm
    As you could see I was trying to link the maths library. The –lName flag will allow you link the libraries.

    Name is nothing but the libm.a. You need to find the the name of the library and try link them this way. That should probably work!


  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > If I do an #include "absolute path", I can get the .h file
    Just use regular < >

    Then this command line
    gcc -I/path/to/header -L/path/to/lib prog.c -lmylib

    /path/to/header/file.h is a file you want to include - as #include <file.h>
    /path/to/lib is where you'll find libmylib.a
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Sep 2008

    Thank You

    All of those options work from the command line, however, there's a little more to get that going within Xcode. Just in case anyone else has the same problem as I, here is what you need to do.

    to do so you need to right click on the target (on the left menu under Targets) and click get info
    from there, scroll down to header Search Paths and enter the location of the header, and then in Library Search Paths, enter the path of the .a file. This is equivalent of -I/path/to/header -L/path/to/lib.
    After that you need to drag the .a file into the files list, which is equivalent of -lmylib.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with linking to other c++ libraries via .net
    By pipercubusa in forum C++ Programming
    Replies: 0
    Last Post: 05-02-2005, 01:08 PM
  2. Linking and Libraries
    By krygen in forum C++ Programming
    Replies: 14
    Last Post: 12-26-2004, 03:01 PM
  3. Two questions (Linking Libraries and Creating Them)
    By Thantos in forum Linux Programming
    Replies: 3
    Last Post: 03-21-2004, 05:01 PM
  4. Dynamically linking libraries
    By neandrake in forum Windows Programming
    Replies: 5
    Last Post: 06-18-2003, 02:54 PM
  5. Linking .h files to libraries
    By sean in forum C++ Programming
    Replies: 2
    Last Post: 10-27-2001, 08:20 PM