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). This is a simple C program that uses gvc.h, which is a library that comes with a graphical interface. 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 an error

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

I suspect this is a simple fix, but no combination of gcc options that I tried worked.

+4
source share
1 answer

You specified the path to the lib object, but not the path to the header file that should be included. Your compilation command should look 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 suggested that -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 that some versions of gcc use the source file to determine which lib files will actually be linked, so you may need to specify the .c file to the path / link files:

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

All Articles