构建共享库时出现未定义的隐藏符号“__dso_handle”错误

Mon*_*nku 5 c++ ld

我正在尝试构建我的应用程序组件之一的共享库(在 linux 上)。

我正在使用以下命令来创建它:

g++ -g -shared -Wl,--cref,-Map,ComponentA.map -o ComponentA.so \
 ../../components/componentA_all.o -nostdlib -lgcc
Run Code Online (Sandbox Code Playgroud)

在链接阶段,我收到以下错误:

/home/manik/components/componentA.cpp:218: undefined reference to `__dso_handle'
/usr/bin/ld: ../../components/componentA_all.o: relocation R_386_GOTOFF against undefined hidden symbol `__dso_handle' can not be used when making a shared object
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
makefile:188: recipe for target 'ComponentA.so' failed
Run Code Online (Sandbox Code Playgroud)

如果我在“componentA.cpp”中有静态类数组,例如:

static component_info_a cx_objs[10];
Run Code Online (Sandbox Code Playgroud)

错误源的行号位于此位置。我不明白错误的原因是什么。struct component_info_a 的声明写在同一个 componentA.cpp 文件中。

此源文件的链接阶段之前的编译命令是:

g++ -Wp,-MMD,componentA.d -pthread -pipe -c -Woverloaded-virtual  -DUSING_X11 -g -D_REENTRANT -pthread -fpic  -I../.. -I/usr/share -frandom-seed=componentA.cpp -fno-stack-protector -Wall   -fno-inline -o componentA.o componentA.cpp 
Run Code Online (Sandbox Code Playgroud)

配方“componentA_all.o”还有其他源文件,它们是:

componentA.cpp
componentA_drag.cpp
componentA_multitouch.cpp
Run Code Online (Sandbox Code Playgroud)

makefile 用于创建“componentA_all.o”的命令是:

ld -r -o componentA_all.o componentA_drag.o componentA_multitouch.o
Run Code Online (Sandbox Code Playgroud)