编译时出现多重定义错误

Multiple definitions error while compiling

编译时出现多重定义错误,例如

multiple definition of `__data_start'
multiple definition of `_init'

我在论坛上阅读,在他们谈论 makefile 的答案中,但我没有使用 makefile 进行编译,只是 gcc。

我的编译语句是:

gcc -Wall -Werror -O -o textbuffer.c textbuffer

问题出在你的编译语句上

gcc -Wall -Werror -O -o textbuffer.c textbuffer

根据gcc manual-o开关用于表示输出文件

-o file

Place output in file file. This applies to whatever sort of output is being produced, whether it be an executable file, an object file, an assembler file or preprocessed C code.

因此,从本质上讲,您的编译语句应该如下所示

 gcc -Wall -Werror -O textbuffer.c -o textbuffer

**使用:在声明中**

#ifndef
#define __data_start
#define __init
#endif