visual-studio 如何在 Visual Studio 中设置 DLL 文件的路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2119539/
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
How do I set the path to a DLL file in Visual Studio?
提问by sivabudh
I developed an application that depends on a DLL file. When I debugmy application, the applicationwould complain that:
我开发了一个依赖于 DLL 文件的应用程序。当我调试我的应用程序时,应用程序会抱怨:
"This application has failed to start because xxx.dll was not found."
“此应用程序无法启动,因为找不到 xxx.dll。”
So I have to copy the DLL file into the same directory as my .vcproj file.
所以我必须将 DLL 文件复制到与我的 .vcproj 文件相同的目录中。
Is there a way to set the project to look for the DLL file in (preferably) some relative path or (not preferred) some absolute path?
有没有办法设置项目以在(最好)某个相对路径或(非首选)某个绝对路径中查找 DLL 文件?
Similar concept to how we set include and library path in the project settings.
类似于我们如何在项目设置中设置包含和库路径的概念。
I mean when I debugmy application (hitting F5) the above error would pop up.
我的意思是当我调试我的应用程序(点击F5)时,上面的错误会弹出。
回答by sivabudh
- Go to project properties (Alt+F7)
- Under Debugging, look to the right
- There's an Environment field.
- Add your relative path there (relative to vcproj folder) i.e. ..\some-framework\lib by appending
PATH=%PATH%;$(ProjectDir)\some-framework\libor prepending to the pathPATH=C:\some-framework\lib;%PATH% - Hit F5 (debug) again and it should work.
- 转到项目属性 (Alt+F7)
- 在调试下,向右看
- 有一个环境字段。
- 在那里添加您的相对路径(相对于 vcproj 文件夹)即 ..\some-framework\lib 通过附加
PATH=%PATH%;$(ProjectDir)\some-framework\lib或预先添加到路径PATH=C:\some-framework\lib;%PATH% - 再次按 F5(调试),它应该可以工作。
回答by i_am_jorf
The search path that the loader uses when you call LoadLibrary() can be altered by using the SetDllDirectory()function. So you could just call this and add the path to your dependency before you load it.
可以使用SetDllDirectory()函数更改调用 LoadLibrary() 时加载程序使用的搜索路径。因此,您可以调用它并在加载之前将路径添加到您的依赖项。
See also DLL Search Order.
另请参阅DLL 搜索顺序。
回答by kravits88
Go through project properties -> Reference Paths
浏览项目属性 -> 参考路径
Then add folder with DLL's
然后添加带有 DLL 的文件夹
回答by Mark Wilkins
Another possibility would be to set the Working Directoryunder the debugging options to be the directory that has that DLL.
另一种可能性是Working Directory将调试选项下的设置为具有该 DLL 的目录。
Edit: I was going to mention using a batch file to start Visual Studio (and set the PATH variable in the batch file). So then did a bit of searching and see that this exact same question was asked not long ago in this post. The answer suggests the batch file option as well as project settings that apparently may do the job (I did not test it).
编辑:我将提到使用批处理文件启动 Visual Studio(并在批处理文件中设置 PATH 变量)。然后进行了一些搜索,发现不久前在这篇文章中提出了这个完全相同的问题。答案建议批处理文件选项以及显然可以完成工作的项目设置(我没有测试它)。
回答by Joma
In your Project properties(Right click on project, click on property button) ? Configuration Properties ? Build Events ? Post Build Events ? Command Line.
在您的项目属性中(右键单击项目,单击属性按钮)?配置属性 ? 构建事件?构建后事件 ? 命令行。
Edit and add one instruction to command line. for example copy botan.dll from source path to location where is being executed the program.
编辑并向命令行添加一条指令。例如将 botan.dll 从源路径复制到正在执行程序的位置。
copy /Y "$(SolutionDir)ProjectDirs\x64\Botan\lib\botan.dll" "$(TargetDir)"
回答by TheOriginalCole
I know this question had been answered years ago, but for those like me who needed to change where the debugger starts the application, change the command property under Project Properties -> Debugging.
我知道这个问题早在几年前就有人回答了,但是对于像我这样需要更改调试器启动应用程序位置的人,请更改 Project Properties -> Debugging 下的 command 属性。


