Reputation: 565
I'm trying to compile a project using libpng on Mac OS X Yosemite.
I got the error:
Undefined symbols for architecture x86_64:
"_png_create_info_struct", referenced from:
_writePNG in qrenc.o
"_png_create_write_struct", referenced from:
_writePNG in qrenc.o
"_png_destroy_write_struct", referenced from:
_writePNG in qrenc.o
"_png_init_io", referenced from:
_writePNG in qrenc.o
"_png_set_IHDR", referenced from:
_writePNG in qrenc.o
"_png_set_PLTE", referenced from:
_writePNG in qrenc.o
"_png_set_longjmp_fn", referenced from:
_writePNG in qrenc.o
"_png_set_pHYs", referenced from:
_writePNG in qrenc.o
"_png_set_tRNS", referenced from:
_writePNG in qrenc.o
"_png_write_end", referenced from:
_writePNG in qrenc.o
"_png_write_info", referenced from:
_writePNG in qrenc.o
"_png_write_row", referenced from:
_writePNG in qrenc.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
so I added -lpng to my ld call. Now it throws
duplicate symbol _main in:
.obj/main.o
.obj/qrenc.o
ld: 1 duplicate symbol for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Same error when linking against libpng installed by homebrew.
What am I doing wrong?
Upvotes: 1
Views: 542
Reputation: 8861
You have two files (probably main.c and qrenc.c) with main function. Remove the function from any of these files and use -lpng.
Upvotes: 3