Linux——错误报告合集(1)
Linux报错合集
1、fopen.c:11:29: error: ‘errno’ undeclared (first use in this function); did you mean ‘perror’?
printf("open:%s",strerror(errno));
未声明错误:加上头文件后者在使用的文件中声明。
2、warning: implicit declaration of function ‘strerror’
警告: 表示strerror函数隐示的声明 解决方法:include 添加对应的头文件。
3、Segmentation fault (core dumped)
段错误:有很多种可能,一般为操作非法地址,数组越界、关闭未打开的文件等问题。
4、fgets.c:13:23: error: too few arguments to function ‘fgets’
ptintf("gets = %c\n",fgets(fp));
^~~~~
In file included from fgets.c:1:0:
/usr/include/stdio.h:564:14: note: declared here
extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
参数传入太少无法使用fgets,想写fgetc来着写错了
5、fgets.c:35:14: error: ‘w’ undeclared (first use in this function)
if(fput(rec,w) == -1)
传入参数错误fgets第一个参数是要写入的字符第二参数是打开的文件(结构体指针)。
6、fgets.c:35:5: warning: implicit declaration of function ‘fput’; did you mean ‘fputs’? [-Wimplicit-function-declaration]
if(fput(rec,"w") == -1)
^~~~
fputs
非常经典的警告又少写一个字母,应该是fputc或者fputs
7、fputc: Bad file descriptor
打开的文件按是只读模式,没有写权限。
8、gcc: error: fgrtc.c: No such file or directory
gcc: fatal error: no input files
没有这个文件,可能是打错名字了
9、fread.c:13:14: warning: implicit declaration of function ‘malloc’ [-Wimplicit-function-declaration]
buff=(char*)malloc(100);
^~~~~~
fread.c:13:14: warning: incompatible implicit declaration of built-in function ‘malloc’
fread.c:13:14: note: include ‘<stdlib.h>’ or provide a declaration of ‘malloc’
fread.c:28:5: warning: implicit declaration of function ‘free’ [-Wimplicit-function-declaration]
free(buff);
^~~~
fread.c:28:5: warning: incompatible implicit declaration of built-in function ‘free’
fread.c:28:5: note: include ‘<stdlib.h>’ or provide a declaration of ‘free’
这俩函数都需要调用stdlib库
10、fflush.c:8:3: warning: implicit declaration of function ‘sleep’ [-Wimplicit-function-declaration]
sleep(1);
没有调用unistd头文件
11、 fseek.c:16:14: error: ‘seek_CUR’ undeclared (first use in this function); did you mean ‘SEEK_CUR’?
fseek(fp,-2,seek_CUR);
^~~~~~~~
SEEK_CUR
C语言区分大小写。
12、wsystime.c:16:13: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘time_t {aka long int}’ [-Wformat=]
printf("ctime=%d\n",ctime);
类型不对用强制类型转换
13、/tmp/cc7jpdvG.o: In function `main':
test.c:(.text+0x15): undefined reference to `hello'
test.c:(.text+0x1f): undefined reference to `bye'
collect2: error: ld returned 1 exit status
含义:表示hello函数和bye函数在编译的源码内没有找到实现
解决:实现代码或者找到对应函数的库并且链接它。
14、./test: error while loading shared libraries: libmyheby.so: cannot open shared object file: No such file or directory
含义:可执行文件所使用的动态库找不到
解决办法:
因为动态库会先在系统的lib里找所以找到动态库,添加到/usr/lib里面
//不提倡因为会把自己的lib库搞乱
或者使用export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:你的动态库目录
添加在~/.bashrc 文件里面
使用source ~/.bashrc 生效。
15、 thread.c: In function ‘main’:
thread.c:13:33: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type [-Wincompatible-pointer-types]
ret = pthread_create(&tid,NULL,testThread,NULL);
^~~~~~~~~~
In file included from thread.c:3:0:
/usr/include/pthread.h:234:12: note: expected ‘void * (*)(void *)’ but argument is of type ‘int * (*)(char *)’
extern int pthread_create (pthread_t *__restrict __newthread,
意义:表示pthread_create参数3的定义和实际代码不符合,期望的是void * (*)(void *) ,实际的代码是int * (*)(char *)
解决方法:改为pthread_create(&tid,NULL,(void*)testThread,NULL);
16、/tmp/ccWgaZF4.o: In function `main':
thread.c:(.text+0x4b): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
表示pthread_create这个函数没有实现
解决方法:编译时候加 -lpthread
17、thread.c: In function ‘testThread’:
thread.c:10:35: warning: dereferencing ‘void *’ pointer
printf("input arg=%d\n",(int) *arg);
^~~~
thread.c:10:29: error: invalid use of void expression
printf("input arg=%d\n",(int) *arg);
改成*(int *)arg 或者直接(int)arg
18、
编译错误:
error: ‘ThreadPool {aka struct ThreadPool}’ has no member named ‘head’
意义:ThreadPool 结构体没有head这个成员。
解决:检查是否拼写错误。
19、
error: too few arguments to function ‘pthread_mutex_init’
意思:pthread_mutex_init这个函数参数少了
解决:检查函数的参数,添加对应的参数
更多推荐
所有评论(0)