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.
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
using -l flag
gcc -o myCode -Wall myCode.c /usr/lib/libm.a
As you could see I was trying to link the maths library. The –lName flag will allow you link the libraries.
gcc -o myCode -Wall myCode.c -lm
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!
> 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
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.