我在Linux上使用gcc并为静态库创建共享库。我不希望导出某些静态库中的符号。
gcc版本是4.8.0。
我在gcc
命令处尝试此选项但它无效:
-Wl, - exclude-libs,libabc.a。
如果我使用此选项,它会删除所有符号,而不是我想要的符号。
-Wl, - exclude-libs,ALL
有人可以帮助我们使用--exclude-option
而不是从特定的静态库中导出符号吗?
由于 钱德拉
答案 0 :(得分:3)
请忽略我的评论提问,这是不正确的。
最小例子:
test1.c:
int testvar1;
int test1(void) {
return 1;
}
test2.c中:
extern int testvar1;
int test1(void);
int test2(void) {
testvar1 = -1;
return test1() + 2;
}
test.c的:
#include <stdio.h>
#include <dlfcn.h>
int main(int argc, char **argv) {
void *lib = dlopen("./libtest2.so", RTLD_NOW);
int (*f)(void) = dlsym(lib, "test2");
printf("%d\n", f());
return 0;
}
构建
$ gcc -fPIC -c test1.c
$ ar cru libtest1.a test1.o
$ gcc -fPIC -c test2.c
$ gcc -shared -o libtest2.so test2.o -L. -ltest1 -Wl,--exclude-libs,libtest1.a
$ gcc test.c -ldl
$ ./a.out
3
$ readelf --syms -D libtest2.so | grep test1
$