GNU构建系统问题

Din*_*esh 6 c linker

如何找到包含特定功能定义的库?我收到链接器错误.

unw*_*ind 4

您可以使用nm命令行工具列出二进制文件中导出的符号:

~/src> cat nm-test.c

static int plus_four(int x)
{
        return x + 4;
}

int sum_plus_four(int a, int b)
{
        return plus_four(a + b);
}

int product_plus_four(int a, int b)
{
        return plus_four(a * b);
}
~/src> gcc -c nm-test.c
~/src> nm ./nm-test.o
00000000 t plus_four
00000023 T product_plus_four
0000000b T sum_plus_four
Run Code Online (Sandbox Code Playgroud)

根据手册,“t”表示该符号位于代码(文本)段中,大写表示该符号是公共的。

如果您有正在寻找的符号,您可以使用nm使库导出的符号可供 grep 等访问:

$ find -name lib*.a /example/library/path | xargs nm | grep -E "T $SYMBOL_TO_FIND"
Run Code Online (Sandbox Code Playgroud)

该命令行是未经测试的草图,但它应该显示概念。