Tag: 多重定义错误

main()的多重定义

嗨伙计们试图使用两个main()并获得此错误多次定义main()。 我重命名了我的主要function然后为什么是这个错误,并且首先在这里为我的print()定义。 头文件: #ifndef TOP_H_ #define TOP_H_ #include #include #define onemain main #define twomain main inline void print(); #endif /* TOP_H_ */ c文件一: #include “top.h” void print(); int onemain() { print(); return 0; } void print() { printf(“hello one”); } c文件二: #include “top.h” void print(); int twomain() { print(); return 0; } void print() { […]

“多重定义”,“此处首次定义”错误

我有3个项目: 服务器 , 客户端和共享 。 在Commons中创建头和源对不会导致任何问题,我可以从服务器和客户端免费访问这些function。 但是,由于某些原因,在服务器或客户端项目中创建其他源/头文件总是会导致multiple definition of (…)并且first defined here错误。 例: commands.h (在Client项目的根目录中) #ifndef COMMANDS_H_ #define COMMANDS_H_ #include “commands.c” void f123(); #endif /* COMMANDS_H_ */ commands.c (在Client项目的根目录中) void f123(){ } main.c (在Client项目的根目录中) #include “commands.h” int main(int argc, char** argv){ } 错误: make: *** [Client] Error 1 Client first defined here Client multiple definition […]

多个定义和仅标头库

我有一个带有几个c和h文件的C程序。 我决定将程序的一部分设置为“仅限标题”,因此我将代码从c移到了h。 现在我得到了多重定义问题,我不明白为什么。 例如: main.c includes utils.h vector.c includes utils.h 我将utils.c中的所有内容移动到utils.h(当然从项目中删除了utils.c)。 utils.h以。开头 #ifndef UTILS_H_ #define UTILS_H_ // and end with: #endif 为了确保我的警卫是独一无二的,我尝试改变它(例如:UTILS718171_H_),但它不起作用。 仍然,编译器抱怨: /tmp/ccOE6i1l.o: In function `compare_int’: ivector.c:(.text+0x0): multiple definition of `compare_int’ /tmp/ccwjCVGi.o:main.c:(.text+0x660): first defined here /tmp/ccOE6i1l.o: In function `compare_int2′: ivector.c:(.text+0x20): multiple definition of `compare_int2′ /tmp/ccwjCVGi.o:main.c:(.text+0x6e0): first defined here /tmp/ccOE6i1l.o: In function `matrix_alloc’: ivector.c:(.text+0x40): multiple […]