DLL dependency not found when debugging with Visua

2019-02-21 15:57发布

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.

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.

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!

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

3条回答
虎瘦雄心在
2楼-- · 2019-02-21 16:46

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

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.

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.

查看更多
不美不萌又怎样
3楼-- · 2019-02-21 16:51

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

  1. You can drive the IDE from the command line with devenv which has a /useenv switch.

    "... 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

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 
查看更多
We Are One
4楼-- · 2019-02-21 17:04

Go to the project's properties:

Configuration Properties | Debugging | Environment 

And add the following item:

PATH=c:\path\where\the\dll-is;$(Path)
查看更多
登录 后发表回答