gcc -Wl,--exclude-libs,<library.a> 不起作用

Cha*_*ndu 0 gcc symbols ld

我在 Linux 上使用 gcc 并为静态库创建共享库。我不想导出某些静态库中的符号。

gcc版本是4.8.0。

我在命令中尝试此选项gcc,但它不起作用:

-Wl,--排除库,libabc.a 。

如果我使用此选项,它将删除所有不是我想要的符号:

-Wl,--排除库,全部

有人可以帮助如何使用--exclude-option而不是从特定静态库导出符号吗?

谢谢钱德拉

kel*_*tar 6

请忽略我对问题的评论,这是不正确的。

最小的例子:

测试1.c:

int testvar1;
int test1(void) {
    return 1;
}
Run Code Online (Sandbox Code Playgroud)

测试2.c:

extern int testvar1;
int test1(void);

int test2(void) {
    testvar1 = -1;
    return test1() + 2;
}
Run Code Online (Sandbox Code Playgroud)

测试.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;
}
Run Code Online (Sandbox Code Playgroud)

建造:

$ 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
$
Run Code Online (Sandbox Code Playgroud)