Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linking to a dynamic library installed with Homebrew using gcc?

I am trying to compile a program with GCC 4.2.1 that requires a library that was installed with Homebrew on Mac OS X (10.8.3). It's a simple C program that uses gvc.h, which is a library that comes with graphviz. The folder /usr/local/Cellar/graphviz/2.28.0/lib contains both libgvc.dylib and libgvc.6.dylib, but when I try

gcc -L/usr/local/Cellar/graphviz/2.28.0/lib -lgvc simple.c

I get the error

simple.c:1:17: error: gvc.h: No such file or directory

I suspect there's a simple fix to this, but no combination of gcc options that I've tried has worked.

like image 739
David Pfau Avatar asked Apr 13 '13 20:04

David Pfau


1 Answers

You've specified the path to the lib object, but not the path to the header file that needs to be included. Your command to compile needs to be something like this:

gcc -I/usr/local/Cellar/graphviz/2.28.0/include  -L/usr/local/Cellar/graphviz/2.28.0/lib -lgvc simple.c

(I've assumed -I/usr/.../2.28.0/include is where you can find gvc.h; if you're not sure, use locate *gvc.h to find the path.)

Note also, some versions of gcc use the source file to determine what lib files will actually be linked, so you may need to specify the .c file before the link paths/files:

gcc -I/usr/local/Cellar/graphviz/2.28.0/include simple.c -L/usr/local/Cellar/graphviz/2.28.0/lib -lgvc
                                                ^^^^^^^^
like image 106
maditya Avatar answered Sep 22 '22 10:09

maditya