0

我有一个名为 setlocal 的变量和一个名为 void SetLocal(void) 的函数

我正在使用 C51 keil 编译器构建代码,链接器给出以下错误:

“外部属性不匹配公共”

函数和变量不能使用相同的名称吗?有不同的情况?

4

1 回答 1

3

That particular compiler is for embedded systems (using the 8051 chips) and is really targeted for those environments. I've seen compilers in that arena that don't even support floating point, and Keil make it clear that, while it's based on C90, there are deviations from that standard.

As per the compiler limitations listed on the Keil website:

Names may be up to 255 characters long. The C language provides for case sensitivity in regard to function and variable names. However, for compatibility reasons, all names in the object file appear in capital letters. It is therefore irrelevant if an external object name within the source program is written in capital or small letters.

So it's a safe bet that, as far as the linker is concerned, you have a conflict between the setlocal variable and the SetLocal function, both of which would be seen as SETLOCAL.

That also explains (as stated in one on your comments) why changing the variable name to setlocal1 fixes your problem. While the symbols are not case sensitive, they are unique to 255 characters.

于 2015-01-02T06:57:33.893 回答