Portaudio.dll 不会 link 在 VS 中正确

Portaudio.dll won't link properly in VS

我在 visual studio 2019 年使用 C++,在尝试 link 我的项目到 PortAudio 时遇到问题。我收到错误 'portaudio_x64.dll was not found. Reinstalling the program may fix this problem'。 我在属性->配置属性->linker->输入->附加依赖项中 linked 到 portaudio.lib。我还将 .lib 文件所在的文件夹放在 Properties->Configuration properties->Linker->General->Additional library directories 中。 portaudio.h所在文件夹的路径在属性->配置属性->C/C++->常规->附加包含目录。为了更好地衡量,我尝试在我的头文件选项卡中使用 portaudio.h 文件进行编译,并且不使用。 这里有人建议我将实际的 dll 文件复制到与我的解决方案相同的文件夹中。这在我 运行 使用 Crtl+F5 的程序时有效,但是当我构建解决方案并打开 exe 时,我得到与以前相同的错误。我真的很难看到这个问题,任何帮助都会很棒

EXE 使用的 DLL 需要与 EXE 运行所在的目录相同(您的 当前工作目录 ),或者在系统 PATH 中(包括诸如C:\Windows\System32\).

Someone here suggested that I copy the actual dll file into the same folder as my solution. This works when I run the program with Crtl+F5

调试时Visual Studio设置的当前工作目录就是你的解决方案文件夹。

but when I build the solution and open the exe, I get the same error as before

您在这里没有使用 Visual Studio:当前工作目录是您从中打开 EXE 的位置。如果它在资源管理器中,它可能是 EXE 所在的文件夹。如果它在 cmd.exe 中,它就是您导航到的任何地方!

理想情况下,您应将 DLL 保留在您的解决方案文件夹中,但将其作为依赖项或资源添加到您的项目中,以便在构建时将其复制到与 EXE 相同的位置。