是否可以静态链接共享对象? [英] Is it possible to statically link against a shared object?

查看:84
本文介绍了是否可以静态链接共享对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题与该问题不同。 / p>

我正在开发一个具有独立二进制文件的项目,该二进制文件没有动态/外部链接,并且在* nix环境中运行。



我正在尝试使用一个较新的工具集进行构建,但是旧工具集所提供的某些静态库现在不可用,例如,提供了 _start 在此工具集中未提供。



我一直在研究供应商工具集随附的文件,并找到了一些带有符号的共享对象我需要来自crt库(例如 _start,_fini 等),但是我不确定是否有直接将共享库静态链接到二进制文件并进一步使该二进制文件可执行的直接方法。



简短版本:非共享对象二进制文件可以作为sta吗

解决方案

共享库与静态对象之间存在根本的区别图书馆。首先,请在此站点上搜索以前的讨论,然后查看此问题(以及答案)。



基本上,静态库只是对象的集合,链接器将符号名称解析为固定地址- -这是静态链接所必需的。另一方面,共享库更像是一个独立的可执行文件,它由加载程序加载到内存中,并具有程序跳转到的入口地址。但是,链接共享库时,通常不会保留静态库具有的重定位表,因此通常无法从链接的共享库内部提取可链接的对象代码。


My question is not the same as this question.

I'm working on a project with a standalone binary that has no dynamic/external linkage, and runs in a *nix environment.

I'm attempting to move to a newer toolset to build with, but some of the static libraries that are available with the older toolset aren't available now -- for example, the crt libraries that provided _start aren't provided in this toolset.

I've been digging through the files provided with the vendor's toolset and found some shared objects with the symbols I needed from the crt libraries (eg, _start, _fini, etc) but I'm unsure whether there's a straightforward way to statically link a shared object into a binary, and further have that binary be executable.

Short version: Can a non-shared-object binary be statically linked with a shared object without the result becoming another shared object?

解决方案

There's a fundamental difference between a shared library and a static library. First off, do search this site for previous discussions, and check out this question too (and the answers therein).

Basically, a static library is just a collection of objects, and the linker resolves the symbol names into fixed addresses -- this is required for static linking. On the other hand, a shared library is much more like an independent executable, which is loaded into memory by the loader and has entry point addresses to which the program jumps. However, relocation tables that static libraries have are generally not preserved when a shared library is being linked, so it's in general not possible to extract linkable object code from inside a linked shared library.

这篇关于是否可以静态链接共享对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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