用arm-linux-gcc-2.95.3编译,出现 testfb.c:74: parse error at end of input错误
#include
#include
#include
#include
#include
int main(int argc, char *argv [])
{
int fbfd = 0;
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
long int screensize = 0;
char *fbp = 0;
int x = 0, y = 0;
long int location = 0;
/* 以读写方式打开显示设备节点文件/dev/fb0 */
fbfd = open("/dev/fb0", O_RDWR);
if (fbfd <= 0)
{
printf("Error: cannot open framebuffer device.\n");
return -1;
}
printf("The framebuffer device was opened successfully.\n");
/* 得到framebuffer设备的固定屏幕信息*/
if (ioctl(fbfd, FBIOGET_FSCREENINFO, &finfo))
{
printf("Error reading fixed information.\n");
return -2;
}
/* 得到可变屏幕信息*/
if (ioctl(fbfd, FBIOGET_VSCREENINFO, &vinfo))
{
printf("Error reading variable information.\n");
/* 将映射的显存的大小*/
screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
/* 将显存映射到用户空间*/
fbp = (char *)mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);
if ((int)fbp == -1)
{
printf("Error: failed to map framebuffer device to memory.\n");
return -4;
}
printf("The framebuffer device was mapped to memory successfully.\n");
x = 100; y = 100; //Where we are going to put the pixel
/* 在显存上彩色画渐变矩形条*/
for (y = 100; y < 200; y++)
{
for (x = 100; x < 300; x++) {
location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) + (y+vinfo.yoffset) * finfo.line_length;
/* 简单处理,假定是32位或者是16位565模式*/
if (vinfo.bits_per_pixel == 32)
{
*(fbp + location) = 100; // Some blue
*(fbp + location + 1) = 15+(x-100)/2; // A little green
*(fbp + location + 2) = 200-(y-100)/5; // A lot of red
*(fbp + location + 3) = 0; // No transparency
}
else
{ //assume 16bpp
unsigned short b = 10;
unsigned short g = (x-100)/6; // A little green
unsigned short r = 31-(y-100)/16; // A lot of red
unsigned short t = r<<11 | g << 5 | b;
*((unsigned short *)(fbp + location)) = t;
}
}
}
munmap(fbp, screensize);
printf("The framebuffer device was munmapped to memory successfully.\n");
close(fbfd);
printf("The framebuffer device was closed successfully.\n");
return 0;
}
如果用arm-linux-gcc-4.3.2编译,则提示testfb.c:73: error: expected declaration or statement at end of input。 (程序一共73行)
加了两行空行,用2.95.3编译器,就变成
testfb.c:76: parse error at end of input
用4.3.2编译器,还是testfb.c:73: error: expected declaration or statement at end of input
回复 4楼 wonderglass 的帖子
把行列对齐 好好看一下是不是少个括号啊?
我只是大概看了一下!
回复 5楼 daicheng 的帖子
楼上正解,我拿到UE里面看了一下,的确少一个大括号。
for (x = 100; x < 300; x++) {
这个后面猫了一个大括号,楼主看一下就应该能改过来了。
[ 本帖最后由 wangjiafu1985 于 2010-2-3 17:40 编辑 ]
只有求知欲,没有求偶欲的人是植物,只有求偶欲,没有求知欲的人叫动物,既没求知欲,又没求偶欲的人是矿物。
刚才用-E选项预处理,通过了,说明所有头文件都找到了。用-S编译时提示上述错误。
哈哈,刚才没看到回帖又发了个贴,当我楼上这个贴没有发。 我开始也是怀疑括号没对齐,特意到VC下去对了下。没想到还是漏了个。谢谢大家哈。编译通过了。