MinGw32需要静态链接时的Compliation问题(ADOL-C链接ColPack)

时间:2012-08-28 16:15:05

标签: linker mingw

我有一个数学库(ADOL-C),需要链接到其他库(ColPack)以执行某些可选任务。

我可以在Linux中编译它们,在Windows中单独使用ADOl-C或ColPack,但是当我尝试在Windows中使用ColPack编译ADOL-C时(MinGW 32,ld 2.22)我有以下问题:

$ make
Making all in ADOL-C
make[1]: Entering directory `/c/tests/ADOL-C-2.3.0/ADOL-C'
[...]
  CC     int_reverse_s.lo
  CC     int_reverse_t.lo
  CXXLD  libadolc.la

*** Warning: This system can not link to static lib archive /usr/lib/libColPack.
la.
*** I have the capability to make that library automatically link in when
*** you link to this library.  But I can only do this if you have a
*** shared version of the library, which you do not appear to have.
Creating library file: .libs/libadolc.dll.a
sparse/.libs/libsparse.a(sparsedrivers.o): In function `generate_seed_jac':
c:\tests\ADOL-C-2.3.0\ADOL-C\src\sparse/sparsedrivers.cpp:119: undefined referen
ce to `ColPack::BipartiteGraphPartialColoringInterface::BipartiteGraphPartialCol
oringInterface(int, ...)'

[...]
collect2: ld returned 1 exit status
make[5]: *** [libadolc.la] Error 1
make[5]: Leaving directory `/c/tests/ADOL-C-2.3.0/ADOL-C/src'
make[4]: *** [all-recursive] Error 1

我不能像在MinGW中那样提供动态库,即使我使用--enable-shared配置ColPack,我从来没有从其编译中获得任何共享库,只有libColPack。[a | la | lai]和ColPack.exe。

任何提示?

1 个答案:

答案 0 :(得分:1)

花了一点时间,直到我解决了问题。

下载Colpack-1.0.8.tar.gz并使用以下环境对其进行测试

Msys / mingw 4.7.0。

正如您所说,您无法使用它来创建共享库。 过了一段时间,我发现了一个更复杂的解决方案。从这个基础上我发现了一个更短的方式。

简短解决方案:

打开配置

第#行 _ __ _ __ _ __ _ 更改 _ __ _ __ _ __ _ __ _ __ _ 到__

7660        enable_dlopen=no      set it to yes
7663        enable_win32_dll=no   set it to yes
7673        enable_shared=no      set it to yes
7710        enable_static=yes     set it to no
7717        enable_static=yes     set it to no  
8721        enable_shared_with_static_runtimes=no      set it to yes
11797       enable_shared_with_static_runtimes_CXX=no  set it to yes

保存并运行

./configure --disable-static --enable-shared

打开 libtool

第#行 _ __ _ __ _ __ _ 更改 _ __ _ __ _ __ _ __ _ __ _ 到__

5547        allow_undefined=yes   set it to no
5550        allow_undefined=yes   set it to no

保存并运行

make clean
make
.lib 目录中的

现在应该是关注文件。

ColPack.exe      .. 30.08.2012
libColPack.la    .. 30.08.2012
libColPack.lai   .. 30.08.2012
libColPack-0.dll .. 30.08.2012
libColPack.dll.a .. 30.08.2012
libColPack-0.dll

中取出

Export Table:
  Name:                          libColPack-0.dll
  Time Date Stamp:               0x503F3A43 (30.08.2012 11:02:43)
  Version:                       0.00
  Ordinal Base:                  1
  Number of Functions:           883
  Number of Names:               883

  Ordinal   Entry Point   Name
        1   0x000012FC    _Z10createArgsiPPKcRSt6vectorISsSaISsEE
        2   0x00011034    _Z10toFileBiPCSsSsSt6vectorISsSaISsEES1_St3mapISsbSt4lessISsESaISt4pairIKSsbEEE
        3   0x00001FB0    _Z11mm_is_validPc
        ........
libColPack.la

中取出

# libColPack.la - a libtool library file
# Generated by libtool (GNU libtool) 2.4 
#
# Please DO NOT delete this file!
# It is necessary for linking the library.

# The name that we can dlopen(3).
dlname='libColPack-0.dll'

# Names of this library.
library_names='libColPack.dll.a'

......

希望有所帮助!

注意:

没有测试过“make install”!

兼具静态和动态:

将libColPack.la,libColPack.lai和libColPack.dll.a移动到另一个文件夹。我们需要他们,他们将被覆盖。删除文件libColPack.la,目录级别更高。

将libtool文件更改回原始状态(2行)。

运行“make”

你将有一个新的libColPack.a

将libColPack.dll.a移回.libs

将两个先前移动的文件的内容与新的libColPack.la(.lai)合并。

将更新后的libColPack.la复制到目录级别更高的位置。

新的混音文件:libColPack.la

# libColPack.la - a libtool library file
# Generated by libtool (GNU libtool) 2.4 
#
# Please DO NOT delete this file!
# It is necessary for linking the library.

# The name that we can dlopen(3).
dlname='libColPack-0.dll'

# Names of this library.
library_names='libColPack.dll.a'

....

# The name of the static archive.
old_library='libColPack.a'
....

通过这个技巧,您可以同时拥有静态和动态库