Hi all,
I just installed gd2 using mac ports (sudo install gd2), which installed libraries in the following places:
/opt/local/include/gd.h
/opt/local/lib/libgd.dylib (link)
/opt/local/lib/libgd.la
/opt/local/lib/libgd.a
Here is my make file also:
dev: main.o
g++ -L/opt/local/lib -I/opt/local/include -lgd -lpng -lz -ljpeg -lfreetype -lm main.o -o heatmap
main.o: main.cpp
g++ -c main.cpp
So when I create my c++ app I add '#include "gd.h"', which throws:
main.cpp:4:16: error: gd.h: No such file or directory
If I set gd.h as an absolute path (as above)(not a solution, but was curious), I am thrown:
g++ -L/opt/local/include -L/opt/local/lib main.o -o heatmap
Undefined symbols:
"_gdImagePng", referenced from:
_main in main.o
"_gdImageLine", referenced from:
_main in main.o
"_gdImageColorAllocate", referenced from:
_main in main.o
_main in main.o
"_gdImageDestroy", referenced from:
_main in main.o
"_gdImageCreate", referenced from:
_main in main.o
"_gdImageJpeg", referenced from:
_main in main.o
ld: symbol(s) not found
So, I understand this means that ld can not find the libraries it needs (hence trying to give it hints with the "-L" values). So after giving g++ the -L hints and the absolute path in #include, I can get it to work, but I don't think I have to do this, how can I make g++/ld search int eh right places for the libraries?
Drew J. Sonne.
PS. using: - OSX 10.6.2 - gcc version 4.2.1 (Apple Inc. build 5646) (dot 1)
EDIT:
Ok, so after taking into account stfanB and Michael's answer, I've recompiled gd into a local directory (libraries
) and thus, I've changed that first line of my Makefile (I will def check out cmake) to g++ -L./libraries/lib -I./libraries/include -lgd -lpng -lz -ljpeg -lfreetype -lm main.o -o heatmap
But I'm still getting main.cpp:3:16: error: gd.h: No such file or directory
EDIT: Thanks all for the answers, here's my final (working) makefile for anyone else who many want an answer:
dev: main.o
g++ -I./libraries/include -L./libraries/lib -lgd -lpng -lz -ljpeg -lfreetype -lm main.o -o heatmap
main.o: main.cpp
g++ -I./libraries/include -c main.cpp