56 11 C:\Users\Administrator\Desktop\2211030720\main.c [Error] redeclaration of 'i' with no linkage
时间: 2023-11-19 16:04:12 浏览: 130
这个错误通常是由于在同一作用域中重复声明了变量而导致的。在C语言中,变量的作用域通常是在花括号{}内。因此,如果您在同一作用域中声明了两个名称相同的变量,则会出现此错误。
解决此问题的方法是确保您在同一作用域中只声明一次变量。您可以通过以下几种方式解决此问题:
1.将变量的声明移动到更高的作用域中,以确保它只被声明一次。
2.更改变量的名称,以便在同一作用域中没有重复的名称。
3.如果您需要在不同的作用域中使用相同的变量名称,则可以使用关键字extern来声明该变量。这将告诉编译器该变量在其他文件中定义,并且不应该在当前文件中重新定义。
```c
extern int i; // 在其他文件中定义的变量i
int main() {
// 使用变量i
return 0;
}
```
相关问题
54 11 C:\Users\周炎\Desktop\作业\通讯录信息管理系统.c [Error] redeclaration of 'i' with no linkage 出了这个问题怎么办
这个错误提示是因为在同一作用域内重复定义了变量'i',导致编译器无法确定该使用哪一个。解决方法是将重复定义的变量名修改为其他名称或者将其中一个定义删除。
另外,这个错误提示还提到了"no linkage",这是指变量'i'没有外部链接性,也就是说它只能在当前文件中使用,不能被其他文件引用。如果需要在其他文件中使用该变量,需要在定义时加上extern关键字,例如:extern int i;
gsm.h:7:21: fatal error: linkage.h: No such file or directory #include <linkage.h>
这个错误提示是因为编译器无法找到 linkage.h 文件。有可能是因为 linkage.h 文件没有被正确安装或者没有加入编译器的搜索路径中。
你可以尝试以下几个解决方案:
1. 确认 linkage.h 文件是否存在于你的系统中,如果不存在则需要重新安装。
2. 如果 linkage.h 文件存在,那么需要将其所在目录添加到编译器的搜索路径中。可以通过在编译命令中加入 -I 选项来指定头文件所在目录,例如:
```
gcc -I/path/to/linkage.h -o program program.c
```
其中,/path/to/linkage.h 是 linkage.h 文件所在的目录。
3. 如果 linkage.h 文件是你自己编写的,那么需要确认它的命名和路径是否正确,并且需要将其添加到编译命令中进行编译。
希望这些解决方案能够帮助到你。
阅读全文
相关推荐















