本文介绍了从现有对象文件创建共享库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的IDE中有一个项目。我需要使它的共享库在扩展中使用。我不想使用共享库设置复制此项目。有没有办法使用目标文件(.o)从我已经存在的项目构建共享库?正如我所知,我可以为这个写一个makefile。

I have a project in my IDE. I need to make a shared library of it to use in extensions. I don't want to make a copy of this project with shared-library settings. Is there any way to build a shared library using the object files (.o) from my already existing project? As I understand, I can write a makefile for this.

推荐答案

我假设你在某种Unix上,使用GNU工具链。在这种情况下,要创建正确的共享库,您需要使用位置无关代码标志(-fpic或-fPIC)编译代码,然后才能创建共享库。除非你的.o文件已经用这些标志编译,你很可能不会有一个工作的共享库。

I assume you're on some sort of Unix and are probably using the GNU toolchain. In that case, to create a proper shared library, you'd need to compile your code using the position-independent code flags (-fpic or -fPIC) before you can create a shared library. Unless your .o files are already compiled with those flags, chances are you won't end up with a working shared lib.

如果它们已经编译为位置独立代码,通常的 g ++ -shared ... 应该做的。

If they already are compiled for position independent code, the usual g++ -shared ... should do the trick.

这篇关于从现有对象文件创建共享库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 01:24