gcc - 使用 gcc --shared -m64 -Wl,--whole-archive ./*.a 从静态库制作动态库

标签 gcc static-libraries dynamic-library

我收到了这组 gcc 错误,而且我似乎无法从 google 或手册页中得到答案。关于这些意味着什么或从哪里开始寻找的任何见解?

这是生成文件中的行:

#After building several otehr bits of code into static libraries
...
# Grand finally link all the object files into one
        gcc --shared  \
        -m64 \
        -Wl,--whole-archive ./release64/*.a \
        -o ./release64/libMYLIB.so.1.0
        ln -sf libArcGIS.so.1.0 ./release64/libMYLIB.so
        ln -sf libArcGIS.so.1.0 ./release64/libMYLIB.so.1

我收到以下错误(还有更多我选择了前 n 只是为了提供一个想法:
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_muldi3.o): In function `__multi3':
(.text+0x0): multiple definition of `__multi3'
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_muldi3.o):(.text+0x0): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_negdi2.o): In function `__negti2':
(.text+0x0): multiple definition of `__negti2'
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_negdi2.o):(.text+0x0): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_lshrdi3.o): In function `__lshrti3':
(.text+0x0): multiple definition of `__lshrti3'
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_lshrdi3.o):(.text+0x0): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_ashldi3.o): In function `__ashlti3':
(.text+0x0): multiple definition of `__ashlti3'
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_ashldi3.o):(.text+0x0): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_ashrdi3.o): In function `__ashrti3':
(.text+0x0): multiple definition of `__ashrti3'
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_ashrdi3.o):(.text+0x0): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_cmpdi2.o): In function `__cmpti2':
(.text+0x0): multiple definition of `__cmpti2'
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_cmpdi2.o):(.text+0x0): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_ucmpdi2.o): In function `__ucmpti2':
(.text+0x0): multiple definition of `__ucmpti2'
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_ucmpdi2.o):(.text+0x0): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_clear_cache.o): In function `__clear_cache':
(.text+0x0): multiple definition of `__clear_cache'
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_clear_cache.o):(.text+0x0): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_enable_execute_stack.o): In function `__enable_execute_stack':
(.text+0x0): multiple definition of `__enable_execute_stack'
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_enable_execute_stack.o):(.text+0x0): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_absvsi2.o): In function `__absvsi2':
(.text+0x0): multiple definition of `__absvsi2'
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_absvsi2.o):(.text+0x0): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_absvsi2.o): In function `__absvdi2':
(.text+0x20): multiple definition of `__absvdi2'
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_absvsi2.o):(.text+0x20): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_absvdi2.o): In function `__absvti2':
(.text+0x0): multiple definition of `__absvti2'
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_absvdi2.o):(.text+0x0): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_addvsi3.o): In function `__addvsi3':
(.text+0x0): multiple definition of `__addvsi3'
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_addvsi3.o):(.text+0x0): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/libgcc.a(_addvsi3.o): In function `__addvdi3':

更新

我试图结合的静态库是:
-rw-rw-r-- 1 mehoggan mehoggan  487770 Jan  3 11:17 libfreetype.a
-rw-rw-r-- 1 mehoggan mehoggan  227814 Jan  3 11:17 libjpeg.a
-rw-rw-r-- 1 mehoggan mehoggan  258576 Jan  3 11:17 libpng.a
-rw-rw-r-- 1 mehoggan mehoggan 2392136 Jan  3 11:17 libSkia.a
-rw-rw-r-- 1 mehoggan mehoggan  696756 Jan  3 11:17 libSQlite.a
-rw-rw-r-- 1 mehoggan mehoggan 1517832 Jan  3 11:16 libSymbolXLib.a
-rw-rw-r-- 1 mehoggan mehoggan  928934 Jan  3 11:17 libxml2.a

我对每个文件进行了单独编译,因此没有执行链接。我查看了源代码,没有看到任何涉及 libgcc 的内容。这就是为什么错误不会对我造成的原因。

最佳答案

您错过了结束语 --no-whole-archive .那是

    gcc --shared  \
    -m64 \
    -Wl,--whole-archive ./release64/*.a -Wl,--no-whole-archive \
    -o ./release64/libMYLIB.so.1.0
    ln -sf libArcGIS.so.1.0 ./release64/libMYLIB.so
    ln -sf libArcGIS.so.1.0 ./release64/libMYLIB.so.1

没有关闭--no-whole-archive ,初始--whole-archive将影响传递给链接器的所有库,特别是 libgcc,它总是隐式传递。这就是为什么你会得到重复的符号。

关于gcc - 使用 gcc --shared -m64 -Wl,--whole-archive ./*.a 从静态库制作动态库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8716857/

相关文章:

c++ - 静态、共享和可执行 - Windows 和 Linux

c - 获取库中使用的库列表

c - 不理解为什么会出现段错误

c - 将系统调用写入文件描述符零

c++:gcc 是否提供扩展的宏/函数,如 "countof"数组的大小?

testing - 我们如何获得 DejaGnu 中各个测试用例的时间

无法从 Makefile 链接静态库

c++ - 使用所有静态库构建 GDAL

C++ 静态链接共享库

c++ - winapi GetProcessMemoryInfo invalid arguments 问题