我遇到了一个奇怪的问题,但无法在更小的范围内进行模拟。问题是我的符号表有一个我的外部符号条目。这些在头文件中声明。在其他文件中定义 - header.c
头文件
header.h
extern void rlog(int , char*, ...);
extern int SetGDebug(string);
extern int GDebug;
测试.cpp C++文件
#include <header.h>
nm -CA test.o | grep De
00000000 B GDebug
00000b70 t global constructors keyed to GDebug
00000070 T SetGDebug()
编译标志:-Wall -O2 -shared -fPIC -funroll-loops 编译器:g++
这正如预期的那样导致多重重新定义....
另一个快速问题...
extern-nd 符号/函数是否进入目标文件的符号表?
最佳答案
您不需要声明外部函数,只需声明变量。
关于c++ - 目标文件中的外部符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3616299/