2012-09-25 46 views
3

我已经得到了这个错误:静态声明如下我avrstudio4项目非静态

../Indication.c:95:15: error: static declaration of 'menu_boot' follows non-static declaration 

main.c中 i型的#include “indication.h”

指示.h是一个头文件indication.c和功能定义如下:

unsigned char menu_boot(unsigned char index, unsigned char *menu1) 
__attribute__((section(".core"))); 

indication.c我有

#include "indication.h" 
... 
unsigned char menu_boot(unsigned char index, unsigned char *menu1) 

我应该怎么办?

+1

你的.c文件中的内容在签名后还没有'__attribute __((section(“。core”)))''' –

+0

这可能会帮助你http://stackoverflow.com/questions/3148244/static-declaration-follows-non-static-declaration – Jeyaram

+1

你是否在一个系统,其中'Indication.c'和'indication.c'引用相同文件?你的编译错误在'Indication.c'中,所以除非文件系统区分大小写,否则你正在查看错误的文件。 (Mac和Windows通常不区分大小写。)您的GCC版本不会告诉您以前的声明在哪里? –

回答

1

从表面,该错误消息表示在文件../Indication.c(其可以是或可以不是相同的文件名为indication.c您讨论该文件)的95行,对于作为这样menu_boot静态声明:

static unsigned char menu_boot(unsigned char index, unsigned char *menu1); 

或它的静态定义,如:

static unsigned char menu_boot(unsigned char index, unsigned char *menu1) 
{ 
    ... 
} 

考虑下面的代码在FIL Ëxx.c

extern unsigned char function(int abc); 

static unsigned char function(int abc); 

static unsigned char function(int abc) 
{ 
    return abc & 0xFF; 
} 

当与GCC 4.1.2编译(在RHEL 5),编译器说:

$ gcc -c xx.c 
xx.c:3: error: static declaration of ‘function’ follows non-static declaration 
xx.c:1: error: previous declaration of ‘function’ was here 
$ 

如果我注释掉线三条,那么编译器说:

$ gcc -c xx.c 
xx.c:6: error: static declaration of ‘function’ follows non-static declaration 
xx.c:1: error: previous declaration of ‘function’ was here 
$ 

该消息是相同的,但包括有关以前声明位置的信息。在这种情况下,它位于同一个源文件中;如果声明位于翻译单元中包含的不同源文件(通常是标题)中,则会标识其他文件。