且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用IPython进行Python嵌入:WindowsError:[错误193]%1不是有效的Win32应用程序

更新时间:2022-05-08 01:02:58

问题确实与msvcr90.dll有关。解决它的方法是将程序与msvcr90.dll相关联。但是,要链接msvcr90.dll,您需要有一个清单,否则您将收到运行时错误。此清单如下所示:

Problem indeed is related to msvcr90.dll. Way to solve it is to link the program against msvcr90.dll. However, to link against msvcr90.dll you need to have a manifest or you will get a runtime error. This manifest looks like:

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.21022.8" processorArchitecture="amd64" publicKeyToken="1fc8b3b9a1e18e3b"></assemblyIdentity>
    </dependentAssembly>
  </dependency>
</assembly>

我用python.exe从文本编辑器中提取并命名为 msvcr90。清单。此清单使用资源文件链接到应用程序 msvcr90.rc

which I extracted from python.exe with a text editor and named msvcr90.manifest. This manifest is linked into the application using the resource file msvcr90.rc

#include "winuser.h"
1 RT_MANIFEST msvcr90.manifest

使用以下方法编译成目标文件:

which in turned can be compiled into an object file using:

windres msvcr90.rc msvcr90.o

比这个资源文件和msvcr90.dll的程序编译成:

Than, compilation of the program with this resource file and msvcr90.dll becomes:

g++ -I /c/prog64/Python27/include t.cpp /c/prog64/Python27/libs/libpython27.a msvcr90.o msvcr90.dll

其中I从C复制MSVCR90.DLL:/Windows/winsxs/amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b/msvcr90.dll

where I copied msvcr90.dll from c:/Windows/winsxs/amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.21022.8_none_750b37ff97f4f68b/msvcr90.dll

输入来自

  • https://cournape.wordpress.com/2008/09/02/how-to-embed-a-manifest-into-a-dll-with-mingw-tools-only
  • Manifest being ignored in mingw app
  • http://www.mingw.org/wiki/MS_resource_compiler
  • https://lists.launchpad.net/kicad-developers/msg09473.html

和其他一些网页向我解释了如何做到这一点。

and a couple of other web pages which explained me how to do this.