gcc:无法从目标文件创建.so [英] gcc: Not able to create .so from object files

查看:133
本文介绍了gcc:无法从目标文件创建.so的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从* .o文件创建.so动态库,并且面临以下问题.

I am trying to create .so dynamic library from *.o files and facing below issue.

日志:

[nptemp-static]$ gcc -shared *.o -o libexample.so

/usr/bin/ld: bindings_hubbub_parser.o: relocation R_X86_64_32 against `.rodata.str1.8' can not be used when making a shared object; recompile with -fPIC
bindings_hubbub_parser.o: could not read symbols: Bad value
collect2: ld returned 1 exit status

有什么主意吗?我需要使用指定的选项重新编译整个源代码吗?

Any idea? Do I need to recompile my whole source code with the option specified?

实际上,我不知道自己编译的源代码,因为所有源代码都是我按照README中的说明下载和编译的开源代码.

Actually, I am not aware of the source code which I compiled because all the source code is open source which I downloaded and compiled by following instructions in README.

推荐答案

我正在尝试从* .o文件创建.so动态库,并且面临以下问题.

I am trying to create .so dynamic library from *.o files and facing below issue.

这不是那么简单.在实践中,制作共享的库时,应专门编译 (至少在Linux上).

This is not that simple. In practice, you should compile specifically when making a shared library, at least on Linux.

(也许您可能需要编辑 Makefile 或以某种方式进行配置您的构建自动化(如果它不是为构建共享库而设计的;如果是为构建免费软件库,您可以向其作者或社区寻求帮助)

(Perhaps you might need to edit your Makefile or configure somehow your build automation if it was not designed for building a shared library; if building some free software library, you might ask help from its authors or community)

共享库希望具有与位置无关的代码.因此,您需要使用-fPIC标志使用编译其源代码.传递给g++gcc(请参见).您可能还想明确显示 rpath .

Shared libraries want to have position independent code. So you need to compile their source code with the -fPIC flag passed to g++ or gcc (see this). You could also want to explicit the rpath.

阅读Drepper的论文: 如何编写共享库 .

Read Drepper's paper: How To Write Shared Libraries.

这篇关于gcc:无法从目标文件创建.so的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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