visual-studio 在 Visual Studio 中如何在项目属性中给出 .lib 文件的相对路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/132697/
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
In Visual Studio how to give relative path of a .lib file in project properties
提问by AMM
I am building a project using Visual Studio. The project has a dependency on a lib file generated by another project. This project is there is the parent directory of the actual project I am building.
我正在使用 Visual Studio 构建一个项目。该项目依赖于另一个项目生成的 lib 文件。这个项目是我正在构建的实际项目的父目录。
To be more clear, I have a "ParentDir" which has two subDirectories Project1 and Project2 under it. Now Project1 depends on lib generated by Project2.
更清楚地说,我有一个“ParentDir”,它下面有两个子目录 Project1 和 Project2。现在 Project1 依赖于 Project2 生成的 lib。
In the properties of Project1, I am trying to give a relative path using $(SolutionDir)/../ParentDir/Project2/Debug But this does not seem to work.
在 Project1 的属性中,我试图使用 $(SolutionDir)/../ParentDir/Project2/Debug 给出一个相对路径,但这似乎不起作用。
Can you tell me where i am going wrong, or suggest the correct way of achieving this.
你能告诉我我哪里出错了,或者提出实现这一目标的正确方法。
采纳答案by Terminus
Add the dependant project to your solution and set it as a dependency of the other project using project properties. Then it just magically works ;).
将依赖项目添加到您的解决方案中,并使用项目属性将其设置为其他项目的依赖项。然后它就神奇地起作用了;)。
A solution is just a file that describes a set of related (interconnected) projects and the relation between them, so this is the correct way of doing it.
解决方案只是一个描述一组相关(互连)项目以及它们之间关系的文件,因此这是正确的做法。
回答by eugensk
Your current dir is your $(ProjectDir), that is where .vcproj file is.
您当前的目录是您的 $(ProjectDir),即 .vcproj 文件所在的位置。
So, just write ../Project2/Debug, that will do.
所以,只要写../Project2/Debug,就可以了。
Even better, write ../Project2/$(ConfigurationName) for all configurations
更好的是,为所有配置编写 ../Project2/$(ConfigurationName)
thus you will be always linking to the correct version of that lib.
因此,您将始终链接到该库的正确版本。
回答by songuke
I think Visual Studio does not expand the relative path properly when the ".." is placed somewhere in the middle of the path string. It only knows how to expand ..{sub-path}.
我认为当“..”放置在路径字符串中间的某个位置时,Visual Studio 不会正确扩展相对路径。它只知道如何扩展 ..{sub-path}。

