我试图在ubuntu 14.04下编译并运行此代码.我下载并安装了libpng 1.6.12版.我能够使用编译代码gcc test.c -lpng
但是当我尝试运行它时,我收到此错误:
./a.out: error while loading shared libraries: libpng16.so.16: cannot open shared object file: No such file or directory
编辑:
所以我找到了libpng16.so.16,它进入/usr/local/lib
并且我将其复制/usr/local/include/libpng16/
到/usr/local/include/
并重新编译代码,无论如何问题仍然存在.
有什么建议 ?
我试图访问我的C代码中的png像素数据.我找到了这个库libpng.我从这个网站下载了最新版本,我使用的是Ubuntu 14.04.我按照INSTALL文件中的说明操作.一切顺利.然后我尝试用gcc编译这段代码.但我收到了这个:
/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' …
Run Code Online (Sandbox Code Playgroud) 我是在 linux 下编写 c 的新手,所以这可能是一个愚蠢的问题,但我在使用 fopen 时遇到了问题。当我遇到这个问题时,我只是用这个非常简单的代码试了一下:
#include <stdio.h>
#include<stdlib.h>
int main()
{
FILE *test;
if( fopen("test.txt","r") == NULL )
printf("didnt open");
else
printf("opened!");
fclose(test);
}
Run Code Online (Sandbox Code Playgroud)
test.txt 与此代码和 a.out 位于同一文件夹中。当我调试 a.out 时,我得到:
Breakpoint 1, main () at testit.c:14
14 if( fopen("test.txt","r") == NULL )
(gdb) s
_IO_new_fopen (filename=0x400696 "test.txt", mode=0x400694 "r") at iofopen.c:103
103 iofopen.c: No such file or directory.
(gdb) s
__fopen_internal (filename=0x400696 "test.txt", mode=0x400694 "r", is32=1) at iofopen.c:65
65 in iofopen.c
(gdb) c
Continuing.
Program received signal SIGSEGV, …
Run Code Online (Sandbox Code Playgroud)