使用memset、memcpy等函数需要包含string.h而不是strings.h

问题:

frm_package.c中调用了memset()和memcpy()函数,但是没有包含相应的头文件,编译时出现错误:

dingq@wd-u1110:~/hwsvn/2sw/1prj_linux/pdu/src/branches/pdu-isocket/isocket$ make
gcc -g3 -Wall -o0 -c nettrans.c -o nettrans.o
gcc -g3 -Wall -o0 -c tcpclient.c -o tcpclient.o
gcc -g3 -Wall -o0 -c frm_package.c -o frm_package.o
frm_package.c: In function ‘package_frm’:
frm_package.c:96:2: warning: implicit declaration of function ‘memcpy’ [-Wimplicit-function-declaration]
frm_package.c:96:2: warning: incompatible implicit declaration of built-in function ‘memcpy’ [enabled by default]
frm_package.c:97:2: warning: implicit declaration of function ‘memset’ [-Wimplicit-function-declaration]
frm_package.c:97:2: warning: incompatible implicit declaration of built-in function ‘memset’ [enabled by default]
frm_package.c: In function ‘ack_ctrl’:
frm_package.c:231:2: warning: incompatible implicit declaration of built-in function ‘memcpy’ [enabled by default]
frm_package.c:232:2: warning: incompatible implicit declaration of built-in function ‘memset’ [enabled by default]
frm_package.c:246:7: error: ‘ctrls’ undeclared (first use in this function)
frm_package.c:246:7: note: each undeclared identifier is reported only once for each function it appears in
frm_package.c:224:9: warning: variable ‘id’ set but not used [-Wunused-but-set-variable]
frm_package.c: In function ‘parse_ctrl’:
frm_package.c:328:2: warning: implicit declaration of function ‘ctrl_init’ [-Wimplicit-function-declaration]
frm_package.c:348:7: warning: implicit declaration of function ‘ctrl_add’ [-Wimplicit-function-declaration]
frm_package.c:366:5: warning: incompatible implicit declaration of built-in function ‘memcpy’ [enabled by default]
frm_package.c:366:12: error: ‘date_time’ undeclared (first use in this function)
frm_package.c:368:5: warning: implicit declaration of function ‘rtc_write’ [-Wimplicit-function-declaration]
frm_package.c:323:5: warning: unused variable ‘k’ [-Wunused-variable]
make: *** [frm_package.o] Error 1

于是,在frm_package.c中包含了头文件<strings.h>,再次使用make clean;make编译,出现的编译错误还是一模一样。


解决办法:

1. 经查找交叉编译工具链ELDK42下的./arm/usr/include/strings.h文件,确实没有memcpy()和memset();

这是怎么回事呢?

难道是包含的头文件出错了?

到原来使用memset()函数的源文件中去看了下,果然是包含错了,应该包含的是头文件<string.h>,而不是<strings.h>;

改为包含<string.h>,再次编译,错误消失。

问题解决。


你可能感兴趣的:(Date,function,工具,each)