David Carpenter
David Carpenter

Reputation: 1640

G++ linking with libpng

I'm trying to do some image processing using C++. I'm currently using OS X 10.7 and writing my code simply using a makefile and the terminal. I've used macports to install libpng but I still can't link with it.

g++ main.cpp -llibpng -O2 -o ImageManipulator

g++ main.cpp -lpng -O2 -o ImageManipulator

both fail with:

ld: library not found for -lpng

and

ld: library not found for -llibpng

does anyone know how to call g++ for this on OS X?

Upvotes: 1

Views: 3540

Answers (3)

TomFuertes
TomFuertes

Reputation: 7270

Got this error trying to install a gem (Mac OSX / Homebrew). Fixed by running brew update && brew install libpng && brew link libpng --force

Upvotes: 0

cli_hlt
cli_hlt

Reputation: 7164

I dont think macports does add its lib directory to the default path searched by gcc. Try

g++ main.cpp -L/opt/local/lib -lpng -O2 -o ImageManipulator

Upvotes: 3

jeff.vanvoorst
jeff.vanvoorst

Reputation: 119

Use the -L/path/to/library_directory to have g++ know where to find libpng (I have forgotten where mac ports installs the libraries).

Upvotes: 1

Related Questions