接上一篇博客
报错:
错误:‘lt’未声明(在此函数内第一次使用)
for (i = 1; i < argc; i++) {
^
myfiletype.c:11:17: 附注:每个未声明的标识符在其出现的函数内只报告一次
myfiletype.c:11:25: 错误:expected ‘)’ before ‘;’ token
for (i = 1; i < argc; i++) {
^
myfiletype.c:13:23: 错误:‘amp’未声明(在此函数内第一次使用)
if (lstat(argv[i], &buf) < 0) {
^
myfiletype.c:13:26: 错误:expected ‘)’ before ‘;’ token
if (lstat(argv[i], &buf) < 0) {
^
myfiletype.c:13:35: 错误:expected ‘)’ before ‘;’ token
if (lstat(argv[i], &buf) < 0) {
^
原因已找到,代码复制粘贴到notepad++时
多出现了例如 <之类的符号。。。
正确的格式应该是:
#include "ourhdr.h"
int main(void)
{
char *ptr;
int size;
if (chdir("/usr/spool/uucppublic")<0)
err_sys("chdir failed");
ptr = path_alloc(&size); /* our own function */
if (getcwd(ptr, size) == NULL)
err_sys("getcwd failed");
printf("cwd = %s\n", ptr);
exit(0);
}
但又报了新的错:
/tmp/cch8CbP1.o:cdpwd.c:(.text+0x26):对‘err_sys’未定义的引用
/tmp/cch8CbP1.o:cdpwd.c:(.text+0x32):对‘path_alloc’未定义的引用
/tmp/cch8CbP1.o:cdpwd.c:(.text+0x5a):对‘err_sys’未定义的引用
/usr/lib/gcc/i686-pc-cygwin/4.8.2/../../../../i686-pc-cygwin/bin/ld: /tmp/cch8CbP1.o: bad reloc address 0x20 in section `.eh_frame'
/usr/lib/gcc/i686-pc-cygwin/4.8.2/../../../../i686-pc-cygwin/bin/ld: final link failed: 无效的操作
collect2: 错误:ld 返回 1
看了这篇博客 尝试了一下新的方法 但又报了新的错
关于path_alloc()函数
错误:与‘path_alloc’类型冲突
char *path_alloc(int *); /* {Prog pathalloc} */
^
In file included from ourhdr.h:4:0,
from cdpwd.c:1:
/usr/include/apue.h:49:7: 附注:‘path_alloc’的上一个声明在此
char *path_alloc(size_t *); /* {Prog pathalloc} */
^
In file included from cdpwd.c:1:0:
ourhdr.h:28:18: 错误:与‘open_max’类型冲突
int open_max(void); /* {Prog openmax} */
^
In file included from ourhdr.h:4:0,
from cdpwd.c:1:
/usr/include/apue.h:50:7: 附注:‘open_max’的上一个声明在此
long open_max(void); /* {Prog openmax} */
^
In file included from cdpwd.c:1:0:
ourhdr.h:55:18: 错误:与‘ptym_open’类型冲突
int ptym_open(char *); /* {Progs ptyopen_svr4 p yopen_44bsd} */
^
In file included from ourhdr.h:4:0,
from cdpwd.c:1:
/usr/include/apue.h:85:7: 附注:‘ptym_open’的上一个声明在此
int ptym_open(char *, int); /* {Prog ptyopen} */
^
In file included from cdpwd.c:1:0:
ourhdr.h:56:18: 错误:与‘ptys_open’类型冲突
int ptys_open(int, char *); /* {Progs ptyopen_svr4 ptyopen_4 bsd} */
^
In file included from ourhdr.h:4:0,
from cdpwd.c:1:
/usr/include/apue.h:86:7: 附注:‘ptys_open’的上一个声明在此
int ptys_open(char *); /* {Prog ptyopen} */
^
In file included from cdpwd.c:1:0:
ourhdr.h:58:10: 错误:与‘pty_fork’类型冲突
pid_t pty_fork(int *, char *, const struct termios *,
^
In file included from ourhdr.h:4:0,
from cdpwd.c:1:
/usr/include/apue.h:88:8: 附注:‘pty_fork’的上一个声明在此
pid_t pty_fork(int *, char *, int, const struct termios *,
^
In file included from cdpwd.c:1:0:
ourhdr.h:63:0: 警告:“read_lock”重定义 [默认启用]
#define read_lock(fd, offset, whence, len) lock_reg(fd, F_SETLK, F_RDLCK, offset, whence, len)
^
In file included from ourhdr.h:4:0,
from cdpwd.c:1:
/usr/include/apue.h:94:0: 附注:这是先前定义的位置
#define read_lock(fd, offset, whence, len) \
^
In file included from cdpwd.c:1:0:
ourhdr.h:64:0: 警告:“readw_lock”重定义 [默认启用]
#define readw_lock(fd, offset, whence, len) lock_reg(fd, F_SETLKW, F_RDLCK, offset, whence, len)
^
In file included from ourhdr.h:4:0,
from cdpwd.c:1:
/usr/include/apue.h:96:0: 附注:这是先前定义的位置
#define readw_lock(fd, offset, whence, len) \
^
In file included from cdpwd.c:1:0:
ourhdr.h:65:0: 警告:“write_lock”重定义 [默认启用]
#define write_lock(fd, offset, whence, len) lock_reg(fd, F_SETLK, F_WRLCK, offset, whence, len)
^
In file included from ourhdr.h:4:0,
from cdpwd.c:1:
/usr/include/apue.h:98:0: 附注:这是先前定义的位置
#define write_lock(fd, offset, whence, len) \
^
In file included from cdpwd.c:1:0:
ourhdr.h:66:0: 警告:“writew_lock”重定义 [默认启用]
#define writew_lock(fd, offset, whence, len) lock_reg(fd, F_SETLKW, F_WRLCK, offset, whence, len)
^
In file included from ourhdr.h:4:0,
from cdpwd.c:1:
/usr/include/apue.h:100:0: 附注:这是先前定义的位置
#define writew_lock(fd, offset, whence, len) \
^
In file included from cdpwd.c:1:0:
ourhdr.h:67:0: 警告:“un_lock”重定义 [默认启用]
#define un_lock(fd, offset, whence, len) lock_reg(fd, F_SETLK, F_UNLCK, offset, whence, len)
^
In file included from ourhdr.h:4:0,
from cdpwd.c:1:
/usr/include/apue.h:102:0: 附注:这是先前定义的位置
#define un_lock(fd, offset, whence, len) \
^
我现在所做的,就是瞎试错……

博客记录了C代码报错及解决过程。最初代码复制到notepad++出现如<之类符号报错,修正格式后又报新错,如对函数未定义的引用、函数类型冲突、宏重定义等警告和错误,博主目前处于不断试错阶段。

1545

被折叠的 条评论
为什么被折叠?



