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

时间:2022-09-18 12:21:53

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

我使用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!

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.

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

3 个解决方案

#1


6  

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.

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

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.

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

#2


8  

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

确保libmxml.a中的目标文件是使用-fPIC构建的。有必要构建一个共享库。另见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

#3


3  

Linking the shared library libgstmatroskademux.la against the static library

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

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.

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

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

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

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.

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

#1


6  

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.

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

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.

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

#2


8  

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

确保libmxml.a中的目标文件是使用-fPIC构建的。有必要构建一个共享库。另见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

#3


3  

Linking the shared library libgstmatroskademux.la against the static library

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

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.

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

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

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

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.

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