简体   繁体   English

在Visual Studio中,如何在项目属性中提供.lib文件的相对路径

[英]In Visual Studio how to give relative path of a .lib file in project properties

I am building a project using Visual Studio. 我正在使用Visual Studio构建一个项目。 The project has a dependency on a lib file generated by another project. 该项目依赖于另一个项目生成的lib文件。 This project is there is the parent directory of the actual project I am building. 这个项目是我正在构建的实际项目的父目录。

To be more clear, I have a "ParentDir" which has two subDirectories Project1 and Project2 under it. 为了更清楚,我有一个“ParentDir”,它下面有两个子目录Project1和Project2。 Now Project1 depends on lib generated by 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. 你能告诉我哪里出错了,或者建议你找到正确的方法。

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. 解决方案只是一个描述一组相关(互连)项目及其之间关系的文件,因此这是正确的方法。

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. 因此,您将始终链接到该库的正确版本。

I think Visual Studio does not expand the relative path properly when the ".." is placed somewhere in the middle of the path string. 我认为当“..”放在路径字符串中间的某处时,Visual Studio不会正确扩展相对路径。 It only knows how to expand ..{sub-path}. 它只知道如何扩展.. {sub-path}。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM