How to define relative paths in Visual Studio Proj

2019-01-16 11:17发布

I have a library and a console application that uses a library. The library has a folder with source and header files.

My project is in a child/inner directory but that library directory that I want to include is in a parent/upper directory.

My project directory:

H:\Gmail_04\gsasl-1.0\lib\libgsaslMain

Includes files are here:

H:\Gmail_04\gsasl-1.0\src

How can I use paths relative to the project directory, to include folders that are in a parent/upper directory?

5条回答
孤傲高冷的网名
2楼-- · 2019-01-16 11:25

If I get you right, you need ..\..\src

查看更多
Rolldiameter
3楼-- · 2019-01-16 11:31

In Visual Studio 2013 you can look at the properties of any source file. Click on the file via the solution Explorer.

One of those properties is the "Relative Path".

查看更多
该账号已被封号
4楼-- · 2019-01-16 11:38

Instead of using relative paths, you could also use the predefined macros of VS to achieve this.

$(ProjectDir) points to the directory of your .vcproj file, $(SolutionDir) is the directory of the .sln file.

You get a list of available macros when opening a project, go to
Properties → Configuration Properties → C/C++ → General
and hit the three dots:

project properties

In the upcoming dialog, hit Macros to see the macros that are predefined by the Studio (consult MSDN for their meaning):

additional include directories

You can use the Macros by typing $(MACRO_NAME) (note the $ and the round brackets).

查看更多
欢心
5楼-- · 2019-01-16 11:45

I have used a syntax like this before:

$(ProjectDir)..\headers

or

..\headers

As other have pointed out, the starting directory is the one your project file is in(vcproj or vcxproj), not where your main code is located.

查看更多
放荡不羁爱自由
6楼-- · 2019-01-16 11:48

By default, all paths you define will be relative. The question is: relative to what? There are several options:

  1. Specifying a file or a path with nothing before it. For example: "mylib.lib". In that case, the file will be searched at the Output Directory.
  2. If you add "..\", the path will be calculated from the actual path where the .sln file resides.

Please note that following a macro such as $(SolutionDir) there is no need to add a backward slash "\". Just use $(SolutionDir)mylibdir\mylib.lib. In case you just can't get it to work, open the project file externally from Notepad and check it.

查看更多
登录 后发表回答