“警告:将共享库链接到静态库不可移植”是什么意思?

发布于 2024-12-18 21:47:02 字数 676 浏览 1 评论 0原文

我正在通过使用 libmxml.a 库的某些函数来创建一个动态库,但我收到此警告:

*Warning: Linking the shared library libgstmatroskademux.la against the _
*static library /home/Mr32/gst-template4_final/gst-plugin/src/libmxml.a _
is not portable!

我也收到此警告:

gcc: /home/Mr32/gst-template4_final/gst-plugin/src/libmxml.a: linker _
input file unused because linking not done

那么此警告的含义是什么以及如何解决它?

编辑:

有一个已经自动生成的 make 文件用于编译 gstreamer 插件。现在,为了在该插件中使用 libmxml.a 的某些功能,我在 make 文件的 GST_CFLAGS 变量中添加了 $(PATH)/libmxml.a 。现在,当我执行 makemake install 时,插件工作正常,但我仍然收到此警告。

I am making one dynamic library by using some function of libmxml.a library but I get this warning:

*Warning: Linking the shared library libgstmatroskademux.la against the _
*static library /home/Mr32/gst-template4_final/gst-plugin/src/libmxml.a _
is not portable!

I also get this warning:

gcc: /home/Mr32/gst-template4_final/gst-plugin/src/libmxml.a: linker _
input file unused because linking not done

So what's the meaning of this warning and how could I solve it?

Edit :

There is one already autogenerated make file for compiling the gstreamer plugin. Now to use some function of libmxml.a in that plugin I have added $(PATH)/libmxml.a in the GST_CFLAGS variable in the make file. Now, when I do make and make install, the plugin works fine, but I still get this warning.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

回眸一遍 2024-12-25 21:47:02

确保 libmxml.a 中的目标文件是使用 -fPIC 构建的。有必要建立一个共享库。另请参阅 http://tldp.org/HOWTO/Program-Library-HOWTO /shared-libraries.html

这是一个简单的示例

$ cat stat.c 
int five() { return 5; }
$ gcc -c stat.c -fPIC
$ ar crus libstat.a stat.o
$ cat dynamic.c
int ten() { return five() + five(); }
$ gcc -c dynamic.c -fPIC
$ gcc -shared -o libdyn.so dynamic.o -L. -lstat
$ ldd libdyn.so # Just to show static linkage to libstat.a
  linux-vdso.so.1 =>  (0x00007fffca1b8000)
  libc.so.6 => /lib/libc.so.6 (0x00007fc004649000)
  /lib/ld-linux-x86-64.so.2 (0x00007fc004bf7000)
$ cat main.c 
int main() { return ten(); }
$ gcc main.c -L. -ldyn
$ LD_LIBRARY_PATH=. ./a.out 
$ echo $?
10

Ensure that object files in libmxml.a were built with -fPIC. It's necessary to build a shared library. See also http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html

Here's a quick example

$ cat stat.c 
int five() { return 5; }
$ gcc -c stat.c -fPIC
$ ar crus libstat.a stat.o
$ cat dynamic.c
int ten() { return five() + five(); }
$ gcc -c dynamic.c -fPIC
$ gcc -shared -o libdyn.so dynamic.o -L. -lstat
$ ldd libdyn.so # Just to show static linkage to libstat.a
  linux-vdso.so.1 =>  (0x00007fffca1b8000)
  libc.so.6 => /lib/libc.so.6 (0x00007fc004649000)
  /lib/ld-linux-x86-64.so.2 (0x00007fc004bf7000)
$ cat main.c 
int main() { return ten(); }
$ gcc main.c -L. -ldyn
$ LD_LIBRARY_PATH=. ./a.out 
$ echo $?
10
定格我的天空 2024-12-25 21:47:02

将共享库链接到静态库是不可能的(除非您真的非常了解自己在做什么)。不要这样做。

第一个警告来自 libtool。它告诉您,您要求的操作将在不同的系统上执行不同的操作,其中一些操作可能不是您想要的。通常它会以各种惊人的方式失败,因为共享库和静态库中的代码需要使用不同的编译器标志进行编译。

第二个警告来自 gcc。它告诉您在编译时提供静态库是没有意义的。这是因为 CFLAGS 中有 $(PATH)/libmxml.a,它与该位置无关。事实上,大多数时候您不应该有 $(PATH)/libmxml.a,而是 -L$(PATH) -lmxml反而。这仍然应该出现在 LDFLAGS 中,但如果这也进入编译器命令行,gcc 不会抱怨。

Linking shared libraries to static libraries is not possible (unless you really know very well what you are doing). Don't do it.

The first warning is from libtool. It tells you, that the operation you asked for will do different things on different systems and some of those things are probably not what you want. Often it's just going to fail in various spectacular ways, because code that goes in shared and static libraries needs to be compiled with different compiler flags.

The second warning is from gcc. It is telling you that providing static library when compiling is pointless. That's because you have $(PATH)/libmxml.a in CFLAGS, where it has no business of being. In fact, most of the time you should not have $(PATH)/libmxml.a, but -L$(PATH) -lmxml instead. That should still go in LDFLAGS, but gcc won't complain if this makes it to the compiler command-line too.

旧人九事 2024-12-25 21:47:02

将共享库 libgstmatroskademux.la 链接到静态库

这是警告您,如果您尝试在 64 位 Linux 上构建它,它可能会失败。这是因为在 x86_64 上,链接到共享库的所有代码必须使用 -fPIC 标志进行编译,并且代码位于 .a 中图书馆通常不是。

gcc: .../libmxml.a: 未使用链接器输入文件,因为链接未完成

这是警告您有一个伪造的命令行。您很可能正在编译某些内容,并且在命令行上有 -c (这告诉 GCC 在编译源代码后停止,并且执行链接)。由于您还在同一命令行上提供libmxml.a,GCC 意识到您不知道自己在做什么,并警告您(更多)考虑它。

Linking the shared library libgstmatroskademux.la against the static library

This is warning you that if you e.g. tried to build this on 64-bit Linux, it would likely fail. That's because on x86_64, all code that gets linked into a shared library must be compiled with -fPIC flag, and code that lives in .a libraries usually isn't.

gcc: .../libmxml.a: linker input file unused because linking not done

This is warning you that you have a bogus command line. Most likely you are compiling something, and have -c on the command line (which tells GCC to stop after compiling source, and not perform linking). Since you are also supplying libmxml.a on that same command line, GCC realized that you don't know what you are doing, and warned you to think (more) about it.

撑一把青伞 2024-12-25 21:47:02

实际上,恐怕之前所有的答案对第一个警告的解释都是错误的(尤其是已接受的警告)。静态库不可移植的警告很可能源于您硬编码了它的路径(这与生成的 libgstmatroskademux.la 文件实际上包含这条路)。因此,您不必依赖 pkg-config 或 gcc 本身来搜索静态库(这将确保您的项目在多个平台和发行版上成功编译)已使用静态库的固定路径(并且所述路径在其他平台上很可能会有所不同)。修复确实是将 -L$(PATH) -lmxml 传递给 gcc (如已接受答案的第二部分所建议),因为这将确保更大的兼容性,并且将使链接共享库...针对静态库...不可移植!错误也消失。

Actually all the previous answers are wrong on the explanation of the first warning I'm afraid (especially the accepted one). The warning that the static library is not portable most likely stems from the fact that you had the path to it hard-coded (it has to do with the fact that the resulting libgstmatroskademux.la file will actually contain this path). So instead of relying on pkg-config or gcc itself to do the search of static libraries for you (which would ensure that your project compiles successfully on multiple platforms and distros) you've used fixed paths for the static library (and said path would most likely be different on other platforms). The fix is indeed to pass -L$(PATH) -lmxml to gcc (as suggested by the second part of the accepted answer) as this will ensure greater compatibility and will make the Linking the shared library ... against the static library ... is not portable! error go away as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文