C++ 使用 Visual Studio 11 RC 调试时未找到 DLL 依赖项

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12518082/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 16:20:47  来源:igfitidea点击:

DLL dependency not found when debugging with Visual Studio 11 RC

c++dllvisual-studio-2012fmod

提问by hhatinen

My project is a standalone C++ application that uses FMOD for playing sound. I've previously developed the same project with Visual Studio 2010 without any problems, but 2012 gives me the classic error: "The program can't start because fmodex.dll is missing from your computer. Try reinstalling the program to fix this problem." The project seems to load other DLLs(such as Direct3d related files and d3d shader compiler) just fine.

我的项目是一个独立的 C++ 应用程序,它使用 FMOD 播放声音。我之前用 Visual Studio 2010 开发了相同的项目,没有任何问题,但是 2012 给了我经典错误:“程序无法启动,因为您的计算机缺少 fmodex.dll。尝试重新安装程序以解决此问题。 ” 该项目似乎加载其他 DLL(例如 Direct3d 相关文件和 d3d 着色器编译器)就好了。

The problem occurs only if trying to debug or run the program from the IDE, not if I copy the executable to the appropriate directory with DLL and run it manually. If I remove all references to FMOD from the program, the debugging and running works fine. I've made sure that I have correct working directory in Project settings (besides it loads all the other files just fine in the same directory). I originally converted the project from Visual Studio 2010, but tried to create a new project from scratch with no luck. I've also tinkered all the possible compiler and linker settings through, and googling doesn't seem to help either.

只有在尝试从 IDE 调试或运行程序时才会出现问题,如果我将可执行文件复制到带有 DLL 的相应目录并手动运行它,则不会出现问题。如果我从程序中删除对 FMOD 的所有引用,调试和运行工作正常。我确保在项目设置中有正确的工作目录(除了它在同一目录中加载所有其他文件之外)。我最初从 Visual Studio 2010 转换了该项目,但尝试从头开始创建一个新项目,但没有成功。我还修改了所有可能的编译器和链接器设置,谷歌搜索似乎也无济于事。

I'm guessing that the problem has something to do with the new Metro style apps and it's way to handle external dependecies, but I have also turned "Metro Style App Support" off. I'm starting to think I've really tried everything I can and have no idea what to try next. Directions for getting more diagnostic information would be much appreciated as well! Thanks!

我猜这个问题与新的 Metro 风格应用程序有关,它是处理外部依赖的方式,但我也关闭了“Metro 风格应用程序支持”。我开始认为我真的已经尽我所能,但不知道接下来要尝试什么。获得更多诊断信息的方向也将不胜感激!谢谢!

Edit:Visual Studio version I'm using is Visual Studio Ultimate 2012 RC, Version 11.0.50706.0 QRELRC July, 2012

编辑:我使用的 Visual Studio 版本是 Visual Studio Ultimate 2012 RC,版本 11.0.50706.0 QRELRC 2012 年 7 月

回答by Michael Burr

Go to the project's properties:

转到项目的属性:

Configuration Properties | Debugging | Environment 

And add the following item:

并添加以下项目:

PATH=c:\path\where\the\dll-is;$(Path)

回答by reechard

My sympathies, I live in DLL hell a lot lately it seems. Two suggestions:

我的同情,我最近似乎经常生活在 DLL 地狱中。两个建议:

  1. You can drive the IDE from the command line with devenvwhich has a /useenvswitch.

    "... Use PATH, INCLUDE, LIBPATH, and LIB environment variables instead of IDE paths for VC++ builds.

  2. dumpbin /dependents [*.exe] [*.dll]will show you DLL dependencies.

    dumpbin /dependents openssl.exe

  1. 您可以使用命令行驱动IDEdevenv其中有一个/useenv开关。

    "... 使用 PATH、INCLUDE、LIBPATH 和 LIB 环境变量而不是 VC++ 构建的 IDE 路径。

  2. dumpbin /dependents [*.exe] [*.dll]将显示 DLL 依赖项。

    dumpbin /dependents openssl.exe

Microsoft (R) COFF/PE Dumper Version 10.00.40219.01 Copyright (C) Microsoft Corporation. All rights reserved. Dump of file openssl.exe

File Type: EXECUTABLE IMAGE

Image has the following dependencies:

SSLEAY32.dll
LIBEAY32.dll
WSOCK32.dll
MSVCR80.dll
KERNEL32.dll

Summary

     4000 .data
    14000 .rdata
     1000 .rsrc
    33000 .text 

Microsoft (R) COFF/PE Dumper 版本 10.00.40219.01 版权所有 (C) Microsoft Corporation。版权所有。文件 openssl.exe 的转储

文件类型:可执行图像

图像具有以下依赖项:

SSLEAY32.dll
LIBEAY32.dll
WSOCK32.dll
MSVCR80.dll
KERNEL32.dll

Summary

     4000 .data
    14000 .rdata
     1000 .rsrc
    33000 .text 

回答by Leo Davidson

It may be that VS is running the app with a different current directory to when you run the app by hand.

可能是 VS 正在使用与您手动运行应用程序时不同的当前目录运行应用程序。

VS typically sets the current directory to the project folder, which is usually not the same as the folder where the built binaries are. When you run it by hand you're probably running it from the latter, not the former.

VS 通常将当前目录设置为项目文件夹,该文件夹通常与构建的二进制文件所在的文件夹不同。当您手动运行它时,您可能是从后者而不是前者运行它。

If that is the problem then the code that loads fmodex.dll must be depending on the current dir being in the DLL search path, which can a big security risk (lookup "DLL planting" or DLL "pre-loading") and which is actively blocked by some Windows configurations.

如果这是问题,那么加载 fmodex.dll 的代码必须取决于 DLL 搜索路径中的当前目录,这可能会带来很大的安全风险(查找“DLL 种植”或 DLL“预加载”),并且被某些 Windows 配置主动阻止。