我正在尝试编译可在线获取的代码Non-Local Means Denoising
当我编译源代码时,会出现以下错误,我认为这些错误主要归因于libpng
:
g++ -L/opt/local/lib/ -L/usr/local/lib/ -L/usr/lib/x86_64-linux-gnu/ -fopenmp -lpng
-o nlmeans_ipol nlmeans_ipol.o io_png.o libauxiliar.o libdenoising.o mt19937ar.o
io_png.o: In function `io_png_write_raw':
io_png.c:(.text+0xe0): undefined reference to `png_create_write_struct'
io_png.c:(.text+0xf6): undefined reference to `png_create_info_struct'
io_png.c:(.text+0x12b): undefined reference to `png_init_io'
io_png.c:(.text+0x194): undefined reference to `png_set_IHDR'
io_png.c:(.text+0x1a6): undefined reference to `png_write_info'
io_png.c:(.text+0xb36): undefined reference to `png_write_image'
io_png.c:(.text+0xb48): undefined reference to `png_write_end'
io_png.c:(.text+0xb62): undefined reference to `png_destroy_write_struct'
io_png.c:(.text+0xbcc): undefined reference to `png_destroy_write_struct'
io_png.c:(.text+0xc1f): undefined reference to `png_destroy_read_struct'
io_png.c:(.text+0xe6a): undefined reference to `png_destroy_write_struct'
io_png.c:(.text+0xe80): undefined reference to `png_destroy_write_struct'
我已经按照以下线程将文件“libpng.a”放在许多位置,但它没有帮助。
我见过类似的libpng problem here,但没有帮助。
我正在使用ubuntu 12.04。
有人可以告诉我实际会出现什么问题吗?
编辑1 完整的电话如下
g++ -O3 -funroll-loops -fomit-frame-pointer -fno-tree-pre -falign-loops -ffast-math -ftree-vectorize -Wall -Wextra -Wno-write-strings -Wno-deprecated -ansi -fopenmp -c -o nlmeans_ipol.o nlmeans_ipol.cpp
cc -c -o io_png.o io_png.c -O3 -funroll-loops -fomit-frame-pointer -fno-tree-pre -falign-loops -ffast-math -ftree-vectorize -Wall -Wextra -Wno-write-strings -ansi -I/opt/local/include/ -I/usr/local/include/
g++ -c -o libauxiliar.o libauxiliar.cpp -O3 -funroll-loops -fomit-frame-pointer -fno-tree-pre -falign-loops -ffast-math -ftree-vectorize -Wall -Wextra -Wno-write-strings -Wno-deprecated -ansi -fopenmp -I/opt/local/include/ -I/usr/local/include/
g++ -c -o libdenoising.o libdenoising.cpp -O3 -funroll-loops -fomit-frame-pointer -fno-tree-pre -falign-loops -ffast-math -ftree-vectorize -Wall -Wextra -Wno-write-strings -Wno-deprecated -ansi -fopenmp -I/opt/local/include/ -I/usr/local/include/
cc -c -o mt19937ar.o mt19937ar.c -O3 -funroll-loops -fomit-frame-pointer -fno-tree-pre -falign-loops -ffast-math -ftree-vectorize -Wall -Wextra -Wno-write-strings -ansi -I/opt/local/include/ -I/usr/local/include/
g++ -lpng -lm -fopenmp -L/opt/local/lib/ -L/usr/local/lib/ -L/usr/lib/ -L/usr/lib/x86_64-linux-gnu/ -fopenmp -lpng -lpngwriter -lz -lfreetype -o nlmeans_ipol nlmeans_ipol.o io_png.o libauxiliar.o libdenoising.o mt19937ar.o
这是完整的电话。它是一个make文件,上面的转储在命令提示符下出现的副本中。
答案 0 :(得分:2)
尝试更改g++
调用中的参数序列,并在目标文件后面添加-lpng
。链接器按照给定的顺序对参数进行评估,因此当它获得-lpng
时,它还不知道io_png.o
,因此它不会链接库中的必要代码
修改强>
makefile执行的最后一个命令是:
g++ -lpng -lm -fopenmp -L/opt/local/lib/ -L/usr/local/lib/ -L/usr/lib/ -L/usr/lib/x86_64-linux-gnu/ -fopenmp -lpng -lpngwriter -lz -lfreetype -o nlmeans_ipol nlmeans_ipol.o io_png.o libauxiliar.o libdenoising.o mt19937ar.o
如果应该像
那样g++ -L/opt/local/lib/ -L/usr/local/lib/ -L/usr/lib/ -L/usr/lib/x86_64-linux-gnu/ -o nlmeans_ipol nlmeans_ipol.o io_png.o libauxiliar.o libdenoising.o mt19937ar.o -lpng -lm -fopenmp -lpngwriter -lz -lfreetype
我不知道每个库,也许-l...
参数的序列仍然不对