如何从一个共享库导出符号 [英] How to export symbols from a shared library

查看:182
本文介绍了如何从一个共享库导出符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用* .o目标code。使用上Windows主机RVDS编译器文件(C源$ C ​​$ C)创建的共享库(*左右)。

I have created a shared library(*.so) using the *.o object code files(C source code) using RVDS compiler on windows Host.

我这个共享对象链接与一个应用程序(使用Linux主机上ARM目标GCC)并获得可执行文件,运行上产生分段错误。(我知道我必须调试它!)

I link this shared object with a application(using gcc for arm target on linux host) and obtain a executable, which on running generates segmentation fault.(I know i have to debug it!)

而不是创建共享库,如果我创建具有相同的源文件的静态库,然后与应用程序链接,然后执行如预期正常工作的应用程序。

Instead of creating shared library, if I create a static library with same source files, and then link with the application, and then execute the application it works fine as expected.

所以我的问题是: -

So my questions are:-

1。)我需要使用一些结构,从而使得当一个应用程序链接它工作正常输出标记(出口到应用功能)或任何其他标​​志,明确地说,在我的源文件?我们需要怎么做呢?

1.) Do i need to export symbols(functions exported to application) or any other symbols, explicitly, in my source file using some constructs so that it works fine when linked with an application? What is needed and how do i do that?

2)如何共享库的工作?即会,将在库中给出其中函数会被加载并运行地址创建库时给出。如何申请(主())解析地址所在的库函数将被执行?

2.) How does shared library work?, i.e. will the addresses where the functions will be loaded and run, will be given in the library be given when library is created. How does application( main() ) resolve the addresses where the library functions are to be executed?

3)如何静态库的工作,即如何做这个地址规范和解决发生在静态库情况?

3.)How does static library work, i.e. how does this address specification and resolving happen in case of static library?

感谢您。
-AD

Thank You. -AD

推荐答案

这是它的工作原理在Linux上:

This is how it works on linux:

1)不,你不需要做任何事情。你可以,但是,限制出口用gcc变量 -fvisibility 命令行参数,并明确标志出口项目的可见性属性。

1) No, you needn't do anything. You can, however, restrict exporting variables with gcc -fvisibility command line argument and explicitly flag exported entries with the visibility attribute.

2)的可执行文件将拥有它进口的所有功能(这些都是默认可见的所有功能)的表。加载器/连接器将只选择运行前加载库,并填写该表中的地址,这些函数的调用都是间接调用。 (请注意,此适用于共享对象以及)

2) The executable will have a table of all functions it imports (these are all functions with default visibility). The loader/linker will pick an address to load the libraries to and fill this table just before running, the calls to those functions are indirect calls. (Note that this holds for shared objects as well)

3)静态链接是在链接时(这是你编译后)执行。实际的地址取代在装配时,他们是直接调用。

3) Static linking is performed on link-time (which is after you compile). The actual addresses are substituted in the assembly, and they are direct calls.

请注意,有一个名为PIC(位置无关code)的东西。据我所知,这涉及了相同的共享对象数据/函数的引用,因此链接器不需要覆盖一半的库code的加载库的时候,在路的code不做出其自己的数据的任何绝对引用。你可以尝试用它来进行试验。

Note: There is the thing called PIC (position independent code). AFAIK, this deals with references to data/functions in the same shared object, so the linker needn't overwrite half of the code of the library when loading the library, in the way that the code doesn't make any absolute references to its own data. You might try to experiment with it.

这篇关于如何从一个共享库导出符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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