DLL 位于子文件夹而不是应用程序文件夹中

发布于 2024-12-07 04:38:32 字数 417 浏览 1 评论 0原文

使用 VC++ 创建了一个动态 python 文件 (pyd)。使用 cx_freeze,我创建了一个 exe。为了使该程序能够在其他计算机上运行,​​我需要在应用程序文件夹中拥有一个 msvcr100.dll 文件。我确实得到了所需的输出。

然而,Microsoft 的分发许可证明确规定 dll 文件应位于应用程序文件夹内的子文件夹中。子文件夹应命名为“Microsoft.VC100.CRT”。我尝试通过更改项目属性来尝试 MS VC++ 中的设置。事实证明它非常棘手,因为我使用 MSVC++ 的唯一方法是让我的 python 程序使用一些 c 选项并返回一些输出,我可以在我的 python 程序中再次使用这些输出。我已经玩过清单文件(嵌入和不嵌入),还在 VC++ 中设置了附加库目录

任何人都知道我可以做什么让我的 pyd 文件查看 Microsoft.VC100.CRT。

have created a dynamic python file (pyd) using VC++. Using cx_freeze, I have created an exe. In order for this program to work on other computers, I need to have a file msvcr100.dll in the applications folder. And I do get the desired output.

However the distribution license for Microsoft clearly states that the dll files should be in a sub folder within the application folder. The sub folder should be named "Microsoft.VC100.CRT". I have tried playing around with the settings in MS VC++ by changing the project properties. Its proving to be very tricky as the only thing I used MSVC++ was for my python program to use some c option and return some output which I can use again in my python program. I have played around with manifest files (embedding and without embedding), also set the Additional Libraries Directory in VC++

Any one got any ideas as to what I can do to make my pyd file look into the Microsoft.VC100.CRT.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

失与倦" 2024-12-14 04:38:32

我不确定在你的脚本中DLL何时被加载,但假设它被延迟到你可以做一些事情的程度,那么你可以尝试自己加载库:

import os
import ctypes
try:
    here = os.path.dirname(__file__)
except NameError:
    here = os.getcwd()
dll = ctypes.CDLL(os.path.join(here, 'Microsoft.VC100.CRT', 'msvcr100.dll'))
del here

或者使用 pywin32

import os
import win32api
try:
    dll = win32api.LoadLibrary('msvcr100.dll') #Never hurts to try
except win32api.error:
    try:
        here = os.path.dirname(__file__)
    except NameError:
        here = os.getcwd()
    #Just to prove messing with PATH does something.
    os.environ['PATH'] = os.environ['PATH'] + os.pathsep + os.path.join(here, 'Microsoft.VC100.CRT')
    dll = win32api.LoadLibrary('msvcr100.dll') #Give it another crank of the handle.
    #Or alternatively without messing with PATH
    dll = win32api.LoadLibrary(os.path.join(here, 'Microsoft.VC100.CRT', 'msvcr100.dll')) #Give it another alternative crank of the handle.
    del here

I'm not sure when in your script the DLL is loaded, but assuming it's delayed to the point you can do something about it, then you can have a go at loading the library yourself:

import os
import ctypes
try:
    here = os.path.dirname(__file__)
except NameError:
    here = os.getcwd()
dll = ctypes.CDLL(os.path.join(here, 'Microsoft.VC100.CRT', 'msvcr100.dll'))
del here

or with pywin32

import os
import win32api
try:
    dll = win32api.LoadLibrary('msvcr100.dll') #Never hurts to try
except win32api.error:
    try:
        here = os.path.dirname(__file__)
    except NameError:
        here = os.getcwd()
    #Just to prove messing with PATH does something.
    os.environ['PATH'] = os.environ['PATH'] + os.pathsep + os.path.join(here, 'Microsoft.VC100.CRT')
    dll = win32api.LoadLibrary('msvcr100.dll') #Give it another crank of the handle.
    #Or alternatively without messing with PATH
    dll = win32api.LoadLibrary(os.path.join(here, 'Microsoft.VC100.CRT', 'msvcr100.dll')) #Give it another alternative crank of the handle.
    del here
淡水深流 2024-12-14 04:38:32

我创建的动态 python 文件是使用 Visual C++ 2010 编译的。因此,为了使其正常工作,需要 MSVCR100.dll 文件。
然而,由于我还为最终程序创建了一个应用程序 (.exe),因此它依赖于 MSVCR90.dll。
由于微软坚持认为这些 dll 应该位于具有特定名称的文件夹中,因此我不能只将这些文件放在应用程序文件夹中。因此,我所做的是使用 Visual C++ 2008 编译 pyd 文件。然后添加 MSVCR90.dll 文件以及相应的清单以及 MSVCP90.dll 和 MSVCM90.dll 文件。这解决了问题。

我的猜测是,在我的程序运行之前需要两代 C 运行时文件。通过使用 VC++2008 编译 pyd 文件,我有效地将这种依赖性减少到一代。

The dynamic python file I had created was compiled using Visual C++ 2010. Hence in order for it to work, the MSVCR100.dll files were needed.
However as I had also created an application (.exe) of my final program, it depended on MSVCR90.dll.
As Microsoft insist that these dlls should be in a folder with a particular name, I couldn't just place these files in the application folder. Hence what I did was compiled the pyd file using Visual C++ 2008. Then added the MSVCR90.dll file along with the corresponding manifests and MSVCP90.dll and MSVCM90.dll files. This solved the problem.

My guess is that before my program in order to work needed two generations of C run time files. By compiling the pyd file using VC++2008, I effectively reduced that dependancy to one generation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文