1

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

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

$ 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 .

有什么提示吗?

4

1 回答 1

2

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

下载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 行)。

运行“制作”

您将拥有一个新的 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'
....

有了这个技巧,你就有了静态库和动态库

于 2012-08-30T11:33:47.580 回答