g++尝试(失败)静态链接到 libstdc++对于共享对象
我正在尝试使用通过 -fPIC 命令创建的多个 .O 文件创建共享对象。当我使用 -shared 参数运行 g++ 时,它似乎试图静态链接到 libstdc++.a 库,这当然会失败。我试图弄清楚为什么当我不使用 -static-stdc++ 参数时它会自动尝试静态链接。
当我尝试创建共享对象时,出现错误 ...libstdc++.a(ios) relocate R_x86_64_325 against 'vtable for std::ios_base': Cannot be use while make a share object
我使用 -V 参数运行 G++ 并收到可以看到 LD 收到参数 -lstdc++。
I'm trying to create a shared object using a number of .O files created with the -fPIC command. When I run g++ with the -shared argument it appears to be trying to statically link to the libstdc++.a library, which of course fails. I'm trying to figure out why it's automatically trying to link statically when I'm not using the -static-stdc++ argument.
when I try creating the shared object I get the error ...libstdc++.a(ios) relocate R_x86_64_325 against 'vtable for std::ios_base': cannot be used when making a shared object
I ran G++ with the -V argument and received and can see LD receives the argument -lstdc++.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将单个共享对象链接在一起时,您需要从现有的 .o 文件中执行此操作。您无法从现有的 .so 文件执行此操作;这会将这些 .so 文件链接到您的 .so 文件,但不会链接到您的 .so 文件。因此,gcc 寻找并找到 .o 文件 (.a) 的存档并尝试链接它们。但由于它们不是为重定位而编译的(无 -fPIC),因此它们不能用于创建 .so 文件。
您的选择是:
对于第一个(我推荐的)选项,以下内容就足够了(它来自我用于创建 malloc/free 拦截的 makefile .so 文件)
When linking together a single shared object, you need to do this from existing .o files. You can not do this from existing .so files; this would link those .so files to your .so file, but not into your .so file. So gcc seeks out and finds an archive of .o files (.a) and tries to link them. But since those are not compiled for relocation (no -fPIC), these can not be used to create .so files.
Your options are:
For the first (that I would recommend) option the following will suffice (it is from a makefile that I use for creating malloc/free intercepting .so files)
我敢打赌它会首先在其库搜索路径中找到静态库,或者只找到静态库。确保已安装并可以找到合适版本的共享版本。您可能可以
trus
您的 g++ 运行来查找它打开库的顺序。I'll bet it's finding the static library first in its library search path, or ONLY finding the static library. Make sure that the appropriate version of the shared version is installed and can be found. You can probably
truss
your g++ run to hunt down the order in which it's opening libraries.