Dll 即使库链接
我正在使用第三部分DLL,我已经成功地使用了很多年。现在链接器毫无怨言地链接dll库,但exe不加载dll 我最近将32位cygwin升级为64位cygwin。 我正在对32位进行mingw交叉编译。 我正在尝试使用FTDI USB接口FTD2XX dll 我有版本2.04.06 ftd2x lib、.h和dll。 多年来,我一直在成功地使用该dll,但使用的是cygwin和mingw的旧版本。 最近升级到cygwin64 该应用程序似乎与ftd2x.lib链接,没有任何问题。 但当我运行应用程序时,它似乎没有查找或加载ftd2x.dll。 该应用程序运行,但一旦尝试调用FTD2XX dll中的某个内容,就会崩溃 我为并行测试创建了一个简单的hello_dll.dll。这很有效。 app.c会同时调用hello_dll.dll和ftd2x.dll。 Is毫无怨言地启动,成功调用hello_dll中的函数,然后在调用ft2xx.dll时崩溃 (我将lib重命名为ftd2x_2.04.06,以区别于我拥有的其他版本。更新的版本没有更好的效果。) 链接-verbose提供:Dll 即使库链接,dll,cygwin,mingw,cross-compiling,ftdi,Dll,Cygwin,Mingw,Cross Compiling,Ftdi,我正在使用第三部分DLL,我已经成功地使用了很多年。现在链接器毫无怨言地链接dll库,但exe不加载dll 我最近将32位cygwin升级为64位cygwin。 我正在对32位进行mingw交叉编译。 我正在尝试使用FTDI USB接口FTD2XX dll 我有版本2.04.06 ftd2x lib、.h和dll。 多年来,我一直在成功地使用该dll,但使用的是cygwin和mingw的旧版本。 最近升级到cygwin64 该应用程序似乎与ftd2x.lib链接,没有任何问题。 但当我运行应用程
i686-w64-mingw32-gcc -Wall -m32 -g -O2 -c -I . -o app.o app.c
i686-w64-mingw32-gcc -Wall -m32 -o app.exe app.o -Wl,-verbose -L. -lhello_dll -lftd2xx_2.04.06
GNU ld (GNU Binutils) 2.34.50.20200227
Supported emulations:
i386pe
using internal linker script:
<snip>
/usr/lib/gcc/i686-w64-mingw32/9.2.0/../../../../i686-w64-mingw32/bin/ld: mode i386pe
attempt to open /usr/i686-w64-mingw32/sys-root/mingw/lib/../lib/crt2.o succeeded
/usr/i686-w64-mingw32/sys-root/mingw/lib/../lib/crt2.o
attempt to open /usr/lib/gcc/i686-w64-mingw32/9.2.0/crtbegin.o succeeded
/usr/lib/gcc/i686-w64-mingw32/9.2.0/crtbegin.o
attempt to open app.o succeeded
app.o
<snip>
attempt to open ./hello_dll.lib succeeded
./hello_dll.lib
(./hello_dll.lib)d000001.o
(./hello_dll.lib)d000000.o
(./hello_dll.lib)d000002.o
<snip>
attempt to open ./ftd2xx_2.04.06.lib succeeded
./ftd2xx_2.04.06.lib
(./ftd2xx_2.04.06.lib)FTD2XX.dll
(./ftd2xx_2.04.06.lib)FTD2XX.dll
(./ftd2xx_2.04.06.lib)FTD2XX.dll
(./ftd2xx_2.04.06.lib)FTD2XX.dll
i686-w64-mingw32-gcc-Wall-m32-g-O2-c-I-o app.o app.c
i686-w64-mingw32-gcc-Wall-m32-o app.exe app.o-Wl-verbose-L-lhello_dll-lftd2xx_2.04.06
GNU ld(GNU Binutils)2.34.50.20200227
支持的仿真:
i386pe
使用内部链接器脚本:
/usr/lib/gcc/i686-w64-mingw32/9.2.0/../../../../../../../../../i686-w64-mingw32/bin/ld:mode i386pe
尝试打开/usr/i686-w64-mingw32/sys root/mingw/lib/。/lib/crt2.o成功
/usr/i686-w64-mingw32/sys root/mingw/lib/。/lib/crt2.o
尝试打开/usr/lib/gcc/i686-w64-mingw32/9.2.0/crtbegin.o成功
/usr/lib/gcc/i686-w64-mingw32/9.2.0/crtbegin.o
尝试打开应用程序。o成功
应用程序o
尝试打开./hello\u dll.lib成功
./hello\u dll.lib
(./hello_dll.lib)d000001.o
(./hello_dll.lib)d000000.o
(./hello_dll.lib)d000002.o
尝试打开。/ftd2x_2.04.06.lib成功
./ftd2x_2.04.06.lib
(./ftd2x_2.04.06.lib)ftd2x.dll
(./ftd2x_2.04.06.lib)ftd2x.dll
(./ftd2x_2.04.06.lib)ftd2x.dll
(./ftd2x_2.04.06.lib)ftd2x.dll
:::::::::::::
我获得了一个32位兼容的gdb版本。当我运行gdb时:
GNU gdb (GDB) 7.7.50.20140303-cvs
<snip>
This GDB was configured as "i686-pc-mingw32".
<snip>
(gdb) break main
(gdb) Breakpoint 1 at 0x40267b: file app.c, line 28.
(gdb) run
(gdb) Starting program: C:\_d\aaa\pd\src\dll\pathological\app.exe
[New Thread 1428.0x2528]
Breakpoint 1, main (argc=1, argv=0x9b2f70) at app.c:28
28 dostuff();
(gdb) info share
(gdb) From To Syms Read Shared Object Library
0x774e0000 0x77644ccc Yes (*) C:\Windows\SysWOW64\ntdll.dll
0x753d0000 0x754cadec Yes (*) C:\Windows\syswow64\kernel32.dll
0x75ea1000 0x75ee6a3a Yes (*) C:\Windows\syswow64\KernelBase.dll
0x64081000 0x6408a1d8 Yes C:\_d\aaa\pd\src\dll\pathological\hello_dll.dll
0x75041000 0x750eb2c4 Yes (*) C:\Windows\syswow64\msvcrt.dll
(*): Shared library is missing debugging information.
(gdb) A debugging session is active.
(gdb) c
Continuing.
Hello dll. <--- The function in hello_dll.dll prints this.
Program received signal SIGSEGV, Segmentation fault.
0x8000004c in ?? () <----- call to FT_GetLibraryVersion()
(gdb) bt
#0 0x8000004c in ?? ()
#1 0x0040158e in dostuff () at app.c:49
#2 0x00402680 in main (argc=1, argv=0x8e2f70) at app.c:28
(gdb)
GNU gdb(gdb)7.7.50.20140303-cvs
此GDB配置为“i686-pc-mingw32”。
(gdb)主断路器
(gdb)0x40267b处的断点1:文件app.c,第28行。
(gdb)运行
(gdb)启动程序:C:\\U d\aaa\pd\src\dll\physical\app.exe
[新螺纹1428.0x2528]
应用程序c处的主断点1(argc=1,argv=0x9b2f70):28
28多斯塔夫();
(gdb)信息共享
(gdb)从到Syms读取共享对象库
0x774e0000 0x77644ccc Yes(*)C:\Windows\SysWOW64\ntdll.dll
0x753d0000 0x754cadec Yes(*)C:\Windows\syswow64\kernel32.dll
0x75ea1000 0x75ee6a3a是(*)C:\Windows\syswow64\KernelBase.dll
0x64081000 0x6408a1d8是C:\\U d\aaa\pd\src\dll\Physical\hello\U dll.dll
0x75041000 0x750eb2c4是(*)C:\Windows\syswow64\msvcrt.dll
(*):共享库缺少调试信息。
(gdb)调试会话处于活动状态。
(gdb)c
持续的。
你好 解决了
2.34.50.20200227 i686-w64-mingw32-ld.exe中有一个bug。就我所知,无论ftd2x版本如何,它都无法与ftd2x.lib一起工作
2.25.51.20150320和2.29.1.20171006使用ftd2x.lib。我已经恢复到2.29 mingw64-i686-binutils。我又开始运行了。很难在看不到任何实际代码的情况下说出,但是如果您确实在使用dll中的FT_*函数,那么dll应该显示为信息共享
。根据个人经验,我建议将FT dll重命名为32和64,以避免混淆。如果你使用FTDI提供的最新DLL会发生什么?我已经编辑了这篇文章,其中包含了调用DLL的主程序的代码。我不认为我需要发布我的hello_dll代码。它起作用了它应该显示在信息共享中,但它不显示。我开始怀疑名字的装饰。你可以打赌,我很早就检查了版本,并在绘制时仔细检查了。--我有三个版本。我只使用了32位版本。在另一台使用Mingw 5.4.0的计算机上编译并运行良好。使用Mingw 9.2.0在我的主计算机上不工作。已将5.4.0链接器复制到主计算机。作品这本身不是解决办法。我不想在我的主计算机上完全恢复到5.4.0。但很明显,Mingw发生了一些变化。有一个bug报告和一个python脚本来转换MSVC库,但还没有尝试过
<snip>
The Import Tables (interpreted .idata section contents)
vma: Hint Time Forward DLL First
Table Stamp Chain Name Thunk
00006000 0000607c 00000000 00000000 00006218 0000614c
DLL Name: FTD2XX.dll
vma: Hint/Ord Member-Name Bound-To
<----- empty?
00006014 00006080 00000000 00000000 000064f8 00006150
DLL Name: hello_dll.dll
vma: Hint/Ord Member-Name Bound-To
6224 1 hello_dll
00006028 00006088 00000000 00000000 00006554 00006158
DLL Name: KERNEL32.dll
vma: Hint/Ord Member-Name Bound-To
6230 277 DeleteCriticalSection
6248 310 EnterCriticalSection
<snip>
/* app.c
Demonstrates using the function imported from the DLL.
*/
// 200708 pathological case. Based on the simple hello_dll.
//#include <stdlib.h>
// for sleep
#include <unistd.h>
#include <stdio.h>
// for dword
#include <windef.h>
// for lpoverlapped
#include <minwinbase.h>
#include "hello_dll.h"
// My legacy app, and really all others too, use 2.04.06.h
#include "ftd2xx_2.04.06.h"
//#include "ftd2xx_2.02.04.h"
///////////////////////////
void dostuff( void );
void call_ft_listdevices( void );
///////////////////////////
int main(int argc, char** argv)
{
FT_STATUS status;
DWORD libver;
//dostuff();
printf( "Calling hello_dll():\n" );
fflush( stdout );
hello_dll();
fflush( stdout );
printf( "Back from hello_dll()\n" );
fflush( stdout );
sleep( 1 );
printf( "Calling FT_GetLibraryVersion().\n" );
fflush( stdout );
status = FT_GetLibraryVersion( &libver );
if( status == FT_OK ){
printf( "FTD2XX library version 0x%lx\n", libver );
fflush( stdout );
}
else{
printf( "Error reading FTD2XX library version.\n" );
fflush( stdout );
}
// 200710 Adding call to different ft function did
// not result in entries in the import table.
//call_ft_listdevices( );
return 0;
}