我正尝试在我的C代码中访问png像素数据。我找到了这个库libpng。我从这个网站下载了最新版本,我使用的是Ubuntu 14.04。我按照安装文件中的说明操作。一切都很顺利。然后我试着和gcc一起编译这段code。但我收到了这封信:
/tmp/ccWa9LDO.o: In function `read_png_file':
test.c:(.text+0x13c): undefined reference to `png_sig_cmp'
test.c:(.text+0x16f): undefined reference to `png_create_read_struct'
test.c:(.text+0x1a0): undefined reference to `png_create_info_struct'
test.c:(.text+0x1db): undefined reference to `png_set_longjmp_fn'
test.c:(.text+0x20c): undefined reference to `png_init_io'
test.c:(.text+0x220): undefined reference to `png_set_sig_bytes'
test.c:(.text+0x239): undefined reference to `png_read_info'
test.c:(.text+0x252): undefined reference to `png_get_image_width'
test.c:(.text+0x271): undefined reference to `png_get_image_height'
test.c:(.text+0x290): undefined reference to `png_get_color_type'
test.c:(.text+0x2af): undefined reference to `png_get_bit_depth'
test.c:(.text+0x2c4): undefined reference to `png_set_interlace_handling'
test.c:(.text+0x2e3): undefined reference to `png_read_update_info'
test.c:(.text+0x2fc): undefined reference to `png_set_longjmp_fn'
test.c:(.text+0x36f): undefined reference to `png_get_rowbytes'
test.c:(.text+0x3b2): undefined reference to `png_read_image'
/tmp/ccWa9LDO.o: In function `write_png_file':
test.c:(.text+0x430): undefined reference to `png_create_write_struct'
test.c:(.text+0x461): undefined reference to `png_create_info_struct'
test.c:(.text+0x49c): undefined reference to `png_set_longjmp_fn'
test.c:(.text+0x4cd): undefined reference to `png_init_io'
test.c:(.text+0x4e6): undefined reference to `png_set_longjmp_fn'
test.c:(.text+0x559): undefined reference to `png_set_IHDR'
test.c:(.text+0x572): undefined reference to `png_write_info'
test.c:(.text+0x58b): undefined reference to `png_set_longjmp_fn'
test.c:(.text+0x5bf): undefined reference to `png_write_image'
test.c:(.text+0x5d8): undefined reference to `png_set_longjmp_fn'
test.c:(.text+0x607): undefined reference to `png_write_end'
/tmp/ccWa9LDO.o: In function `process_file':
test.c:(.text+0x692): undefined reference to `png_get_color_type'
test.c:(.text+0x6be): undefined reference to `png_get_color_type'
test.c:(.text+0x6db): undefined reference to `png_get_color_type'
collect2: error: ld returned 1 exit status我不理解它,因为我预计如果安装有问题,我会因为包含png.h而得到错误。
发布于 2014-08-28 18:41:09
您在评论中说您使用gcc my_code.c,请尝试
gcc my_code.c -lpng-l标志链接库,在本例中为libpng12-dev。
链接意味着编译器添加来自所有目标文件的代码以创建单个可执行文件。目标文件是单独的编译源代码文件( .o文件)。
发布于 2020-07-30 16:21:45
我不太懂英语,但我会尽力帮助你。
我得到这个问题大约2天,解决方案是如此简单,让我们看看。
尝试这样做:gcc my_code.c -lpng
然后你会得到一些像a.out这样的文件,然后你需要在相同的目录中有一些图片png。
之后,键入以下内容:./a.out png_file.png res.png
输出文件将命名为res.png。
https://stackoverflow.com/questions/25544913
复制相似问题