Search code examples
pythondllgdbdependencieswxpython

import wx failed under GDB python interface, R6034: An application has made an attempt to load the C runtime library incorrectly


I have a self build GDB.exe under WinXP, which is link against python 2.7 dll. The GDB was built under msys+MinGW, so GDB.exe is linked against msvcrt.dll. But the python dll is linked against msvcrt90.dll. See the screen shot below of the dependency walker. dependency walker of gdb.exe Generally, the python interpreter in GDB.exe works quite well, and I can correctly run python pretty printer and other python commands. But I found that the wxPython can not run correctly, see the command log:

GNU gdb (GDB) 7.8.50.20140717-cvs
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "mingw32".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
(gdb) python import wx
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "E:\code\gdb\mybuild\bin\lib\site-packages\wx-3.0-msw\wx\__init__.py", li
ne 45, in <module>
    from wx._core import *
  File "E:\code\gdb\mybuild\bin\lib\site-packages\wx-3.0-msw\wx\_core.py", line
4, in <module>
    import _core_
ImportError: DLL load failed: The specified module could not be found.
Error while executing Python code.
(gdb)

I realize that there are some dlls under folder: E:\code\gdb\mybuild\bin\Lib\site-packages\wx-3.0-msw\wx, such as "core_.pyd" and "wxmsw30u_core_vc90.dll", these dlls were build from Visual C++, and you can see, they are linked to msvcr90.dll and msvcp90.dll. msvcr90.dll and msvcp90.dll dependency

But if I run the same command under python.exe (which is E:\code\gdb\mybuild\bin\python.exe) command line shell, there is not such issue, see the log:

Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>>

Look, I don't have any issue to run import wx command. I also noticed that the python.exe is build against msvc90.dll, see the dependency walker screen shot below:

python.exe dependency

Now, my question is: how to solve this issue? From what I know, the two different kind of DLL (msvcrt.dll and msvcrt90.dll) works peacefully, but why I can't use wxpython? Thank you.


Solution

  • OK, the problem is solved. The reason is that both the pyd file and the dll file under the folder E:\code\gdb\mybuild\bin\Lib\site-packages\wx-3.0-msw\wx need to be associated with a manifest. I manually add the manifest to the pyd file by a tool named Resource Hacker, but I think any tool which can edit the PE file can do this. The pyd file already have some piece of manifest, so I just add more like:

    <dependency>
    <dependentAssembly>
      <assemblyIdentity type='win32' name='Microsoft.VC90.CRT' version='9.0.21022.8' processorArchitecture='x86' publicKeyToken='1fc8b3b9a1e18e3b' />
    </dependentAssembly>
    </dependency>
    

    For the dll file, I just found there are manifest file in a wxpython development package 32-bit binaries for MSVC 9 from official wxPython site, so I just copy the manifest files to the E:\code\gdb\mybuild\bin\Lib\site-packages\wx-3.0-msw\wx.

    I don't have issue now, I can correctly show a wxFrame from GDB's command line.