如何在 VIsual C 中添加运行时 DLL 的路径快车2010项目?

发布于 2024-09-28 21:54:55 字数 728 浏览 5 评论 0原文

我有一些外部依赖项需要加载我的 C++ 程序,例如 boost 或其他库。如果这些 .DLL 库不在 $PATH 中,一旦我运行我的程序,我就会收到“无法加载 DLL”错误消息。为了使这些 .DLL 可以在运行我的程序时加载,我需要将这些路径添加到库目录中。例如:

PATH=$PATH;c:\boost\lib

它有效,但我不喜欢这种愚蠢的解决方案,它使全球环境变得肮脏。另外,我还有很多依赖项需要添加。这样做最糟糕的是,一旦你有不同版本的依赖项,这是非常烦人的。例如,这里你有一个项目A依赖于boost1.3.7,要开发它,你必须更改PATH

PATH=$PATH;c:\boost1.3.7\lib

并且,这里你需要开发另一个项目B,它依赖于boost1.4.4,哦,太好了......改变变量

PATH=$PATH;c:\boost1.4.4\lib

正如您所看到的,这不是一个聪明的解决方案......如果您有多个库要链接,那将是一场真正的噩梦。我想要的是修改 VC++ 项目的属性,仅在运行/调试我的程序时将这些路径添加到 PATH 变量。我尝试添加路径,

VC++ Directories -> Executable Directories

但似乎这是用于构建的路径,而不是用于运行的路径。那么,如何添加 VC++ 项目的路径才能正确运行我的程序呢?

I have some external dependencies to load with my C++ program, like boost or other libraries. If those .DLL of libraries are not in $PATH, once I run my program I got a "can't load the DLL" error message. To make those .DLL can be load when running my program, I need to add those path to libraries directory. For example:

PATH=$PATH;c:\boost\lib

It works, but I don't like this stupid solution, which makes the global environment dirty. Also, I have lots more dependencies to add. The worst thing to do this way is, once you have different version of dependencies, it is very annoying. e.g. Here you have a project A depends on boost1.3.7, to develop it, you have to change the PATH

PATH=$PATH;c:\boost1.3.7\lib

And, here you need to develop another project B which depends on boost1.4.4, oh, great.... change the variable

PATH=$PATH;c:\boost1.4.4\lib

As you can see, this is not a smart solution.... If you have more than one library to link, that would be a real nightmare. What I want is to modify property of VC++ project, add those path to PATH variable only when running/debugging my program. I have tried to add path to

VC++ Directories -> Executable Directories

But it seems that's PATH for building, not for running. So, how can I add paths to my VC++ project for running my program correctly?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

水中月 2024-10-05 21:54:55

不确定为什么您考虑将其添加到 PATH 作为“愚蠢”的解决方案?这是第三方库的一个非常常见的解决方案。如果您想重新分发应用程序,或者只是从命令行运行它而不是在 VS 下运行它,该怎么办?

如果您坚持不修改全局路径,您还可以尝试:

  • 将所需的 dll 添加到可执行文件的目录(= 在多个版本和/或多个构建路径的情况下非常混乱且容易出错)
  • 将所需的 dll 添加到 %WINDIR %/system32 (与上面的注释相同)
  • 创建一个批处理文件来设置所需的 PATH,然后调用 VS。现在VS使用你刚刚设置的PATH,而全局PATH保持不变。
  • 您可以尝试将 dll 安装在 WinSxS 文件夹中,但这并不那么容易。 (例如)

顺便说一句,要解决版本控制问题,请使用符号链接:

mklink /J c:/boost c:/boost1.3.7

然后将 c:/boost 添加到您的 PATH 中。如果版本更改,请更改符号链接而不是环境

not sure why you consider adding it to the PATH as a 'stupid' solution? It is a very common solution for 3rd party libs. What if you want to redistribute your application, or just run it from the command line instead of running it under VS?

if you insist on not modifying the global path, you can also try:

  • add the required dlls to the executable's directory (= very messy and error-prone in case of multiple versions and/or multiple build paths)
  • add the reuired dlls to %WINDIR%/system32 (same remark as above)
  • make a batch file that sets the PATH you want, then invoke VS. Now VS uses the PATH you just set, while the global PATH remains unchanged.
  • ou could try getting dlls installed in the WinSxS folders, but that's not so easy. (for example)

btw to get around the versioning problem, use symlinks:

mklink /J c:/boost c:/boost1.3.7

then add just c:/boost to your PATH. If the version changes, change the symlink instead of the environment

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文