为什么DLL无法复制到输出目录? C ++ Visual Studio [英] Why is the DLL not copied to output directory? C++ Visual Studio

查看:173
本文介绍了为什么DLL无法复制到输出目录? C ++ Visual Studio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设置了一个c ++项目以在Visual Studio中使用DLL.该库具有.h .lib和.dll文件.该程序将编译并运行,并成功使用该库. DLL放置在 source 的根目录中,而不是输出目录中.构建时,我希望将DLL从源复制到输出目录,但不是.我在输出目录中看到的只有3个文件,分别是类型,应用程序,增量链接器文件和程序调试数据库.

I set up a c++ project to use a DLL in visual studio. The library had .h .lib and .dll files. The program compiles and runs, and successfully uses the library. The DLL was put in the root directory of the source, not the output directory. When I build, I expected the DLL to be copied form the source to the output directory, but it's not. All I see in the output directory is 3 files of type, application, incremental linker file, and program debug database.

也许我错了,但我认为DLL必须与输出目录中的可执行文件位于同一文件夹中.那是怎么回事?

Maybe I'm wrong but I thought that the DLL needed to be in the same folder as the executable in the output directory. So what's going on?

推荐答案

这也是我很难找到的东西,但是VS不会为您复制.dll.您必须通过创建一个Post-Build事件来告诉它.查看XCOPY上的链接: https://support.microsoft.com/en-us/kb/240268

This is something I had difficulty finding as well, but VS does not copy the .dll's for you. You have to tell it to by creating a Post-Build event. Check out the link on XCOPY: https://support.microsoft.com/en-us/kb/240268

我需要将一些dll复制到我的目标目录(构建目录)中,因此在项目设置的Post-Build事件中使用了以下内容:

I needed to copy some dll's to my target directory (the build directory) so used the following in a Post-Build event in my project settings:

xcopy $(ProjectDir)openal32.dll $(TargetDir) /Y /D

只需将"openal32.dll"替换为您需要复制的任何dll,并为每个需要复制到目标(生成)目录的dll生成一个新的生成事件.

Just replace "openal32.dll" with whatever dll you need to copy and make a new build event for each dll you need copied to the target (build) directory.

/Y禁止提示确认覆盖 /D指示编译器仅在此版本的dll为较新版本时才进行复制.

/Y suppresses prompting to confirm overwrite /D instructs the compiler to only copy if it's a newer version of the dll on this build.

这篇关于为什么DLL无法复制到输出目录? C ++ Visual Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆