[英]Creating shared library through g++ how to
Where is the official "how to" about creating and understanding technics used in dynamic library. 创建和理解动态库中使用的技术的官方“方法”在哪里? I'm using g++ compiler.
我正在使用g ++编译器。 I've googled this question but I can't find anything official about this.
我已经用谷歌搜索了这个问题,但是我找不到任何官方的信息。
you can create shared library easily for example.. 例如,您可以轻松创建共享库。
i have sample program for multiplication like multiplyNum.cpp
我有乘法的示例程序,例如
multiplyNum.cpp
The -fpic option tells g++ to create position independent code which is needed for shared libraries. -fpic选项告诉g ++创建共享库所需的与位置无关的代码。 my source file reside in
src/
folder. 我的源文件位于
src/
文件夹中。
> g++ -I ./inc -fpic -c src/multiplyNum.cpp -o obj/multiplyNum.o
Finally the shared library is created. 最后,创建共享库。 Note the library name must start with the three letters lib and have the suffix .so .
注意,库名必须以三个字母lib开头,后缀为.so 。
> g++ -shared -o lib/libmultiplyNum.so obj/multiplyNum.o
You can use now libmultiplyNum.so
library in your makefile. 您现在可以在makefile中使用
libmultiplyNum.so
库。
我还建议阅读著名的Drepper论文: 如何编写共享库 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.