我正在尝试使用Mac OS X Yosemite上的libpng编译项目。
我收到了错误:
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)
所以我在我的ld电话中添加了-lpng。 现在它抛出
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)
链接到自制软件安装的libpng时出现相同的错误。
我做错了什么?
答案 0 :(得分:3)
你有两个带main函数的文件(可能是main.c和qrenc.c)。从任何这些文件中删除该函数并使用-lpng。