gpt4 book ai didi

c - GNU 构建系统问题

转载 作者:太空狗 更新时间:2023-10-29 17:23:18 29 4
gpt4 key购买 nike

如何找到包含特定函数定义的库?我收到链接器错误。

最佳答案

您可以使用 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

根据 the manual ,'t'表示该符号在代码(文本)段,大写表示它是公开的。

如果您有正在寻找的符号,您可以使用 nm 使库导出的符号可访问,例如搜索:

$ find -name lib*.a /example/library/path | xargs nm | grep -E "T $SYMBOL_TO_FIND"

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

关于c - GNU 构建系统问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3147131/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com