红联Linux门户
Linux帮助

LINUX串口编程(貌似-I命令把默认路径屏蔽了)

发布时间:2011-06-07 17:58:11来源:红联作者:辛昕
我在写一个LINUX的串口程序
因为要用到serial.h这个头文件,所以我要在gcc的编译命令里指定一个路径。
编译命令:(用makefile的方式)

[font=Times New Roman]
makefile的内容:
KERNELDIR=/usr/src nux-headers-2.6.24-24-server

CC = arm-none-linux-gnueabi-gcc
CFLAGS = -I$(KERNELDIR)/include nux -Wall
Hostserial:

$(CC) $(CFLAGS) -o Hostserial Hostserial.c
clean:
rm -f Hostserial
[/font]


后来,编译出了很多问题,我就先不引用和串口相关的所有函数,我只是在主函数里保留了这一句printf。
printf("Can't open Serial Port!\n");

可是出了一大堆错误。
我个人认为这些错误似乎是,没有找到正确的stdio.h引起的。因为它并没说找不到这个头文件,但是出现了好些很奇怪的错误,比如说,找不到一些别的其实我没引用的头文件
完整错误信息如下:

root@ema3530:/home/ema/COM# make
arm-none-linux-gnueabi-gcc -I/usr/src nux-headers-2.6.24-24-server/include nux -Wall -o Hostserial Hostserial.c
cc1: warning: include location "/usr/include" is unsafe for cross-compilation
cc1: warning: include location "/usr/local/include" is unsafe for cross-compilation
In file included from /usr/include/stdio.h:34,
from Hostserial.c:1:
/usr/src nux-headers-2.6.24-24-server/include nux/stddef.h:4:28: error: linux/compiler.h: No such file or directory
In file included from /usr/include/stdio.h:75,
from Hostserial.c:1:
/usr/include bio.h:332: error: expected specifier-qualifier-list before 'size_t'
/usr/include bio.h:364: error: expected declaration specifiers or '...' before 'size_t'
/usr/include bio.h:373: error: expected declaration specifiers or '...' before 'size_t'
/usr/include bio.h:493: error: expected '=', ',', ';', 'asm' or '__attribute__' before '_IO_sgetn'
In file included from Hostserial.c:1:
/usr/include/stdio.h:312: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:319: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:361: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:363: error: format string argument not a string type
/usr/include/stdio.h:361: warning: conflicting types for built-in function 'snprintf'
/usr/include/stdio.h:365: error: expected declaration specifiers or '...' before 'size_t'
/usr/include/stdio.h:367: error: format string argument not a string type
/usr/include/stdio.h:365: warning: conflicting types for built-in function 'vsnprintf'
/usr/include/stdio.h:678: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fread'
/usr/include/stdio.h:684: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fwrite'
/usr/include/stdio.h:706: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fread_unlocked'
/usr/include/stdio.h:708: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'fwrite_unlocked'
Hostserial.c: In function 'main':
Hostserial.c:10: warning: unused variable 'ch'
Hostserial.c:9: warning: unused variable 'fd'
make: *** [Hostserial] Error 1

我的猜测是:
这种错误,应该是所在的这个路径里,标准头文件不完整
所以,我认为解决的办法应该是保留默认路径,但是,如何指定路径的同时又保留默认路径呢?
这个,我试过修改CPATH,丝毫不起作用

----------------------------------------
也或者是别的错误原因,我刚接触LINUX一两个月,很多不懂,希望各位多多指教,谢谢了!
文章评论

共有 3 条评论

  1. 于 2014-02-24 16:14:44发表:

    你好,问题解决了吗?

  2. limengchun 于 2012-11-21 00:32:42发表:

    新手不懂 帮顶

  3. tvnet 于 2011-06-08 08:49:14发表:

    帮顶