这个错误通常是由重复定义的问题引起的,即在不同的源文件中定义了相同的符号。可以通过以下方法解决:
确认是否存在重复定义,在不同的源文件中搜索相同的符号名称。
在重复定义的源文件中,将符号声明为extern,并在另一个源文件中定义它。
例如,如果在main.c和foo.c中都定义了__bss_start,则必须在一个源文件中添加以下行:
extern char __bss_start;
如果在使用库时遇到此错误,可能是由于库
版
本不兼容或库文件已被损坏。确保使用正确
版
本的库文件,并尝试重新编译。
下面是一个示例程序,其中定义了重复的符号:
main.c:
int global_var;
int main() {
global_var = 123;
return 0;
foo.c:
int global_var; // 重复的定义
编译时会出现以下错误:
$ gcc main.c foo.c -o my_program
ld: error: found local symbol '__bss_start' in global part of symbol table in file /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o
ld: error: found local symbol '__libc_csu_fini' in global part of symbol table in file /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o
ld: error: found local symbol '__libc_csu_init' in global part of symbol table in file /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o
ld: error: found local symbol '__libc_start_main' in global part of symbol table in file /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o
ld: error: found local symbol '__gmon_start__' in global part of symbol table in file /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o
ld: error: found local symbol '__data_start' in global part of symbol table in file /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o
ld: error: found local symbol '__dso_handle