5

I have a MinGW64-compiled DLL (python module), which gives error when loaded:

ImportError: DLL load failed: Invalid access to memory location

The DLL is linked only to 64bit libraries (Dependency Walker confirms that) and has debugging symbols. The code is fairly complex c++11 (around 30 source files), I cannot bisect it. I did successfully compile and tested other module with MinGW64 already, the toolchain works fine.

Some people around the web reported this error for code using SSE2 instructions (those are supported on my hw, and I don't use them explicitly) or reading from global vars which have not yet been initialized (there is a few functions with __attribute__((constructor)), but those should work in MinGW64 just fine, according to what I've read; update: I removed all constructor functions to make sure it was not the cause - it makes no difference).

What would be methods to analyze where is the error coming from?

What I tried:

When I load the DLL in debugger (using ctypes.WinDLL(...)), I unfortunately get only meaningless stacktrace from gdb - obviously, the error is trapped by ntdll.dll and signal is raised, but it does not give any further hints as to where the error came from:

Program received signal SIGTRAP, Trace/breakpoint trap.
0x0000000077c23522 in ntdll!ExpInterlockedPopEntrySListFault16 ()
   from C:\Windows\system32\ntdll.dll
(gdb) warning: HEAP[python.exe]:
warning: Invalid address specified to RtlSizeHeap( 00000000003B0000, 0000000002306830 )


(gdb) bt
#0  0x0000000077c23522 in ntdll!ExpInterlockedPopEntrySListFault16 ()
   from C:\Windows\system32\ntdll.dll
#1  0x0000000077c0c241 in ntdll!RtlZeroHeap ()
   from C:\Windows\system32\ntdll.dll
#2  0x0000000077c0c250 in ntdll!RtlZeroHeap ()
   from C:\Windows\system32\ntdll.dll
#3  0x0000000077c3c130 in ntdll!LdrLoadAlternateResourceModuleEx ()
   from C:\Windows\system32\ntdll.dll
#4  0x00000000003b0000 in ?? ()
#5  0x0000000002306830 in ?? ()
#6  0x00000000003b0000 in ?? ()
#7  0x00000000792e21c0 in ?? ()
#8  0x00000000003b0000 in ?? ()
#9  0x0000000077c3c0ba in ntdll!LdrLoadAlternateResourceModuleEx ()
   from C:\Windows\system32\ntdll.dll
#10 0xffffffffffffffff in ?? ()
#11 0x0000000050000061 in ?? ()
#12 0x0000000000000000 in ?? ()

I also linked the object files with a "hello world" executable, but gdb crashes already when opening the file with Reading symbols from woomain.exe (that's my executable):

gdb crash dialogue

4

4 に答える 4

6

問題は、モジュールのコンパイル時に python が MinGW とは異なる msvcrt にリンクしていたことでした。これはhttp://bugs.python.org/issue16472で報告されています。

于 2013-10-07T10:45:14.083 に答える
0

まあ、これはあなたにとって正しい解決策ではないかもしれませんが、単なるヒントです。ImportError: DLL load failed: Invalid access to memory location.C でプログラムされた Python の独自の拡張機能を作成しようとしたときに、同じエラーが発生しました。プラットフォーム: Windows 32 ビット。

このエラーは、すべての Python 環境 (Spyder、ノートブック、プレーン コンソールなど) の非対話モードだけでなく、対話モードでもランダムに表示されたため、本当に苦痛でした。MinGW と Python の distutils (command) を使用してコードをコンパイルしましたpython setup.py install。コンパイルでは警告やエラーは発生せず、正しいディレクトリに pyd ファイルが生成されました。しかし、このモジュールimport exampleを私の Python コードにインポートしようとすると、不規則にクラッシュしました (通常、モジュールのインポートは 5 回に 1 回しか成功しませんでした)。

奇妙なことに、別のコンピューターでは問題なく動作していました...まあ、最終的に回避策を見つけました.MinGWの新しいバージョンをダウンロードし(Qt SDKディストリビューションに同梱されているバージョンを使用する前に)、モジュールを再度コンパイルしました。その後、クラッシュすることはなくなりました。しかし、体系的な解決策や説明は見つかりませんでした。そのため、pyd ファイルの生成に使用されたコンパイラ (DLL がない可能性がありますか? 正確にはわかりません) と関係がある可能性があります。

于 2013-10-07T07:10:27.057 に答える
0

私にとって、opencv2で次のようなエラーが発生しました:

from .cv2 import *

ImportError: DLL load failed: Invalid access to memory location.

解決策:そのために、opencvモジュールをアンインストールして、もう一度再インストールしました。

アンインストール:

pip uninstall opencv-python

インストール:

pip install opencv-python

今、それは私のために働いています。

于 2020-11-26T06:41:49.003 に答える