簡體   English   中英

使用MinGW-Builds在64位系統上編譯32位exe —編譯32位exe,但鏈接到64位DLL

[英]Using MinGW-Builds to compile a 32-bit exe on a 64-bit system — compiles a 32-bit exe but links against 64-bit DLLs

我正在使用MinGW-Builds在64位系統上編譯32位DLL和exe。 我正在使用m32位標志。 編譯和鏈接階段不會產生任何錯誤。 當我嘗試運行該程序時,我得到:

應用程序無法正確啟動(0xc000007b)。 單擊“確定”關閉該應用程序。

我加載了Dependency Walker並收到以下錯誤消息:

錯誤:找到了具有不同CPU類型的模塊。

確實,Dependency Walker表明我的DLL和可執行文件是32位的。 但是,它鏈接的所有其他內容都是64位。 例如,NTDLL.DLL,MSVCRT.DLL,LIBWINPTHREAD-1.DLL都標記為64位。 因此,我相信我沒有正確地鏈接到32位DLL。

使鏈接程序鏈接到32位DLL而不是64位DLL的命令是什么?

更新

當我運行32位Dependency Walker配置文件模式時,我到底在尋找什么? 我在日志窗口中得到以下輸出:

--------------------------------------------------------------------------------
Starting profile on 3/31/2014 at 10:14:41 PM

Operating System: Microsoft Windows NT/2000/XP/2003/Vista based Media Center (64-bit), version 6.01.7601 Service Pack 1
Program Executable: c:\mingw\msys\1.0\home\samuel\projects\bmd2\build\debug\32\testcore\BMD2TESTCORE.EXE
Program Arguments: 
Starting Directory: C:\MinGW\msys\1.0\home\samuel\projects\bmd2\build\debug\32\testcore\
Search Path: C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\MinGW\bin;C:\MinGW\libexec\gcc\x86_64-pc-mingw32\4.7.0;C:\Users\samuel\gcc\bin;C:\Users\samuel\gcc\libexec\gcc\x86_64-pc-mingw32\4.7.0;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Eclipse\adt-bundle\sdk\platform-tools;C:\Program Files\Eclipse\adt-bundle\sdk\tools;C:\Program Files (x86)\QuickTime\QTSystem\;C:\ant\bin;C:\Java\bin;C:\Program Files\TortoiseSVN\bin;C:\Users\samuel\Desktop\work\bmd2\build\debug\lib

Options Selected:
     Simulate ShellExecute by inserting any App Paths directories into the PATH environment variable.
     Log DllMain calls for process attach and process detach messages.
     Log DllMain calls for all other messages, including thread attach and thread detach.
     Hook the process to gather more detailed dependency information.
     Log LoadLibrary function calls.
     Log GetProcAddress function calls.
     Log thread information.
     Use simple thread numbers instead of actual thread IDs.
     Log first chance exceptions.
     Log debug output messages.
     Log a time stamp with each line of log.
     Automatically open and profile child processes.
--------------------------------------------------------------------------------

00:00:00.000: Started "BMD2TESTCORE.EXE" (process 0x1DC) at address 0x00400000 by thread 1.  Successfully hooked module.
00:00:00.000: Loaded "NTDLL.DLL" at address 0x778C0000 by thread 1.  Successfully hooked module.
00:00:00.031: Loaded "KERNEL32.DLL" at address 0x75510000 by thread 1.  Successfully hooked module.
00:00:00.031: Loaded "KERNELBASE.DLL" at address 0x77340000 by thread 1.  Successfully hooked module.
00:00:00.031: DllMain(0x77340000, DLL_PROCESS_ATTACH, 0x00000000) in "KERNELBASE.DLL" called by thread 1.
00:00:00.031: DllMain(0x77340000, DLL_PROCESS_ATTACH, 0x00000000) in "KERNELBASE.DLL" returned 1 (0x1) by thread 1.
00:00:00.031: DllMain(0x75510000, DLL_PROCESS_ATTACH, 0x00000000) in "KERNEL32.DLL" called by thread 1.
00:00:00.046: DllMain(0x75510000, DLL_PROCESS_ATTACH, 0x00000000) in "KERNEL32.DLL" returned 1 (0x1) by thread 1.
00:00:00.046: Injected "DEPENDS.DLL" at address 0x08370000 by thread 1.
00:00:00.078: DllMain(0x08370000, DLL_PROCESS_ATTACH, 0x00000000) in "DEPENDS.DLL" called by thread 1.
00:00:00.093: DllMain(0x08370000, DLL_PROCESS_ATTACH, 0x00000000) in "DEPENDS.DLL" returned 1 (0x1) by thread 1.
00:00:00.093: Loaded "MSVCRT.DLL" at address 0x75C90000 by thread 1.  Successfully hooked module.

鏈接到DLL時,您無需指定其位數。 您只需指定DLL的名稱。 由加載器決定具有您指定名稱的DLL。

您命名的兩個DLL,ntdll和msvcrt是系統組件。 它們位於system32目錄中。 您的32位進程受文件系統重定向器的約束。 這意味着,當加載程序在system32中查找時,重定向器會將其靜默映射到32位系統目錄syswow64。 這是透明發生的,因此加載程序將找到32位版本的ntdll和msvcrt。

您報告的錯誤代碼是0xC000007B 那是一個NTSTATUS錯誤代碼。 特別是STATUS_INVALID_IMAGE_FORMAT 當您嘗試在32位進程中加載​​64位DLL時,的確是報告的錯誤。 因此,這似乎正在發生。

您已經使用Dependency Walker進行了一些調試。 這是完成這項工作的出色工具,但是在您以(靜態模式)使用它的模式下,有時確實會報告誤報。 聽起來您正在使用Dependency Walker的64位版本。 使用32位版本可能會得到更好的診斷。

也就是說,您真正需要做的是在Dependency Walker的Profile模式下運行程序。 可以在“配置文件”菜單下找到。 執行此操作時,您將從加載程序中獲取診斷流,其中包括由於錯誤STATUS_INVALID_IMAGE_FORMAT而無法加載的DLL的名稱。 到那時,應該弄清楚出了什么問題。

您使用的Dependency Walker錯誤。

64位版本的Dependency Walker不夠智能,無法搜索32位DLL路徑(David的回答說明了如何在程序運行時通過重定向實際使用這些路徑)。

您需要使用32位Dependency Walker來分析32位代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM