Dll 使用坏名称链接动态库
我使用的是没有MSYS的MinGW64(Windows 7),我有以下问题: 我有一个dll,是用C99编写的,它必须有.mexw64后缀才能被Matlab使用。我希望能够将此dll动态链接到另一个dll(mexw64),但gcc不允许我直接链接。我不能进行静态链接,因为两个DLL都有许多相同名称的函数,在创建共享库时不导出它们的符号就可以隐藏这些函数 到目前为止,我已经尝试:Dll 使用坏名称链接动态库,dll,mingw,dynamic-linking,Dll,Mingw,Dynamic Linking,我使用的是没有MSYS的MinGW64(Windows 7),我有以下问题: 我有一个dll,是用C99编写的,它必须有.mexw64后缀才能被Matlab使用。我希望能够将此dll动态链接到另一个dll(mexw64),但gcc不允许我直接链接。我不能进行静态链接,因为两个DLL都有许多相同名称的函数,在创建共享库时不导出它们的符号就可以隐藏这些函数 到目前为止,我已经尝试: 使用mklink创建符号链接(具有正确的后缀和preffix)。这是可行的,但我无法从makefile运行mklink
感谢您的评论。您应该构建一个合适的implib,作为链接器输出或从.def生成 链接器:
$ gcc -shared -o testimpl.mexw64 testimpl.c -Wl,--out-implib,libtestimpl.a
$ dlltool -I libtestimpl.a
testimpl.mexw64
或者,指定显式库
:
$ cat testimpl.def
LIBRARY testimpl.mexw64
EXPORTS
test @1
$ dlltool -d testimpl.def -l libtestimpl.a
$ dlltool -I libtestimpl.a
testimpl.mexw64
最后,链接内容:
$ gcc -o test.exe test.c libtestimpl.a
# or
$ gcc -o test.exe test.c -L. -ltestimpl
$ grep testimpl.mexw64 test.exe
Binary file test.exe matches
您应该构建一个适当的implib,作为链接器输出或从.def生成 链接器:
$ gcc -shared -o testimpl.mexw64 testimpl.c -Wl,--out-implib,libtestimpl.a
$ dlltool -I libtestimpl.a
testimpl.mexw64
或者,指定显式库
:
$ cat testimpl.def
LIBRARY testimpl.mexw64
EXPORTS
test @1
$ dlltool -d testimpl.def -l libtestimpl.a
$ dlltool -I libtestimpl.a
testimpl.mexw64
最后,链接内容:
$ gcc -o test.exe test.c libtestimpl.a
# or
$ gcc -o test.exe test.c -L. -ltestimpl
$ grep testimpl.mexw64 test.exe
Binary file test.exe matches