使用静态库编译PIC对象 [英] Compiling PIC object with static library

查看:281
本文介绍了使用静态库编译PIC对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在linux上生成一个共享库,并且正在使用这个xml解析器"mini xml"来解析我的库的一些xml配置文件.我想要的是不对此xml解析器有任何依赖性,因此我想使用供应商提供的静态libmxml.a库,而不是使用libmxml.so,而libmxml.so也与libmxml.so一起存在,这样我的共享库就可以了部署时不依赖libmxml.我尝试了以下操作,但没有用.

I am generating a shared library on linux and I am using this xml parser "mini xml" to parse some xml config files for my library. The thing I want is not to have any dependency on this xml parser so I want to use the static libmxml.a library provided by the vendor instead of using libmxml.so which is also there along with libmxml.so such that my shared library does not depend on libmxml when deployed. I have tried following but it doesnt work.

gcc -fPIC -o myobject.o-静态-lmxml -c myobject.c

gcc -fPIC -o myobject.o -static -lmxml -c myobject.c

但是会发出警告

链接器输入未使用,因为未完成链接

Linker input unused because linking not done

我想念什么?任何帮助将不胜感激.

What am i missing? Any help would be appreciated.

推荐答案

您需要为此专门构建mxml库,使用PIC代码(-fPIC)创建一个静态库,例如libmxml_pic.a. libmxml.a包含仅适用于可执行文件的位置相关代码(在32位x86上可以运行,但仍然很丑陋).

You need to build the mxml library specially for this, creating a static library with PIC code (-fPIC), say libmxml_pic.a. The libmxml.a contains position-dependent code which is only suitable for executables (on 32-bit x86 it will work but it is still ugly).

您还希望避免从库中导出mxml符号.您可以使用版本脚本(将--version-script传递给ld,请参见文档)和/或通过在编译mxml对象时传递-fvisibility=hidden来执行此操作.

You will also want to avoid exporting the mxml symbols from your library. You can do this with a version script (--version-script to ld, see documentation) and/or by passing -fvisibility=hidden while compiling the mxml objects.

这篇关于使用静态库编译PIC对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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