如何在 VIsual C 中添加运行时 DLL 的路径快车2010项目?
我有一些外部依赖项需要加载我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定为什么您考虑将其添加到 PATH 作为“愚蠢”的解决方案?这是第三方库的一个非常常见的解决方案。如果您想重新分发应用程序,或者只是从命令行运行它而不是在 VS 下运行它,该怎么办?
如果您坚持不修改全局路径,您还可以尝试:
顺便说一句,要解决版本控制问题,请使用符号链接:
然后将 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:
btw to get around the versioning problem, use symlinks:
then add just c:/boost to your PATH. If the version changes, change the symlink instead of the environment