.lib中没有符号. [英] Symbols in .lib are not there in .so

查看:65
本文介绍了.lib中没有符号.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个库文件(.lib),其中有许多功能.我正在尝试从中构建共享对象.但是库中的所有符号都不在库中的共享库中.但是,当我从同一库中生成可执行文件时,这些符号是可见的.

I have a library file (.lib) where there are many functions. I am trying to build a shared object out of it. But non of the symbols in library are there in shared object that are in library. However, when I generate executable out of the same library the symbols are visible.

库有问题吗?我是否需要以适合于创建共享库的格式来编译库?

Is some thing wrong with libraries? Do I need to compile libraries in a format suitable for creating shared object?

推荐答案

链接程序的作用是,它们仅从存档文件 .a 中提取那些解析文件的 .o 文件.未解决的符号.

What linkers do is they pull only those .o files from an archive .a that resolve an unresolved symbol.

当您链接共享库并将仅 .a 文件传递到链接器时,没有未解析的符号,因此没有来自 .a 的目标文件被拉入链接器中.共享库.

When you link a shared library and pass only .a files to the linker, there are no unresolved symbols, hence no object files from .a get pulled into the shared library.

要链接共享库,必须将目标文件编译为与位置无关的代码( .a -fPIC .o 文件是通常在没有此选项的情况下构建),然后链接到共享库中.不需要 .a 文件.

To link a shared library the object files must be compiled as position independent code (-fPIC, .o files for .a are normally built without this option) and then linked into a shared library. No .a files are necessary for that.

链接 .a 文件时的另一种选择是使用 -Wl,-undefined =<显式取消定义 .a 中存在的符号.symbol> 链接器选项.但这并不能很好地扩展,因为它需要从包含 .a 的每个 .o 中至少提及一个符号(假设链接器提取了整个 .o ,而不仅仅是其中的一个符号).

Another option is when linking .a files is to explicitly undefine the symbols that are present in .a using -Wl,--undefined=<symbol> linker option. But this does not scale well because it requires mentioning at least one symbol from each .o comprising .a (assuming the linker pulls in an entire .o, rather than just one symbol from it).

这篇关于.lib中没有符号.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆