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

时间:2012-01-03 18:21:51

标签: gcc static-libraries dynamic-library

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

以下是makefile中的行:

#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的内容。这就是为什么错误不会发生在我身上。

2 个答案:

答案 0 :(得分:14)

您错过了结束--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,它总是隐式传递。这就是你得到重复符号的原因。

答案 1 :(得分:1)

这意味着它所说的。有两个或更多.a文件包含.o文件,其中包含这些函数的定义。特别是,您的目录看起来好像包含libgcc.a上的两个变体或包含它的副本的东西。

根本不要对libgcc.a这样做。要省略libgcc add -nostdlib或甚至-nodefaultlibs。