【发布时间】:2016-12-05 19:17:21
【问题描述】:
我一直在为dlopen 和未定义的符号而苦恼。
到目前为止我已经尝试过的:
libraryA.a 带有函数functionA()
libraryA.so 带有函数functionA()
libraryB.so 正在使用functionA()
使用 dlopen 加载 libraryB.so 的可执行文件。
我得到的是:
undefined symbol: functionA
我如何构建:
图书馆A:
gcc -std=gnu11 -O2 -g -Wall -Wstack-usage=2000 -Werror
-fdiagnostics-color -fPIC -pipe -fsigned-char -fno-asynchronous-unwind-tables
-fno-stack-protector -I../include/ libraryA.c -shared -o libraryA.so
图书馆B:
gcc -std=gnu11 -O2 -g -Wall -Wstack-usage=2000 -Werror -fdiagnostics-color
-fPIC -pipe -fsigned-char -fno-asynchronous-unwind-tables
-fno-stack-protector -I../include/ libraryB.c -shared -o libraryB.so
构建可执行文件:
-std=gnu99 -pipe -fno-strict-aliasing -fsigned-char -fno-asynchronous-unwind-tables
-fno-stack-protector -Wall -Wextra -Wundef -Wno-sign-compare -Wno-unused-parameter
-Wno-packed-bitfield-compat -Wno-misleading-indentation -fomit-frame-pointer
-maccumulate-outgoing-args -fPIC -m64 -g3 -gdwarf-2 -fno-common -Wstrict-prototypes
-Wimplicit -Wno-pointer-sign -c executable.c -o executable libraryA.a
像这样在可执行文件中打开 libraryB:
void *handle = dlopen("libraryB.so", RTLD_LAZY);
if (handle == NULL) {
fprintf( stderr, "Load error (%s)!\n", dlerror());
return NULL;
}
如何解决此问题?我也尝试了标志 -rdynamic 没有成功。我也尝试了不同的 dlopen 标志,但也没有成功。
谁能帮帮我?
【问题讨论】:
标签: c gcc dlopen undefined-symbol