Solve the problem of "VS reports No such file or directory"

    I am using the calcOne project of VS2015 today, and changed the project from the Debug version to the Release version. When compiling, an error "Cannot open the include file: "addFunc.h": No such file or directory" pops up, as shown in Figure (1):

Figure (1) Release version reports "No such file or directory" error

    However, changing the project from the Release version back to the Debug version compiles successfully. Therefore, it is judged that the compilation environments of the Release and Debug versions are different.

    The reason for this problem is that the Release version does not configure the corresponding header file path.
    Solution: Right-click "Project" --> Properties --> Select Release version --> C/C++ --> General -- "Additional include directory, add the corresponding header file.

Method 1 Modify through the property page

    This example is the header file path of addFunc.h: ..\myCommon should be added to the C/C++ accessories include directory, as shown in Figure (2):

Figure (2) In the property page, select the Release version and add the corresponding header file path

    When compiling, select the Release version to compile, as shown in Figure (3) and Figure (4).

Figure (3) Release version should be selected when compiling

Figure (4) The version in the toolbar should be consistent with the version in the property page

    The effect is as follows:

Figure (5) Release version compiled successfully

Method 2 Modify by *.vcxproj

    *.vcxproj is the path configuration file of the VS project, which contains Release and Debug environment configuration items, as follows:
    // *.vcxproj

  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
		//..
      <AdditionalIncludeDirectories>..\myCommon;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ClCompile>	
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      //..
      <AdditionalIncludeDirectories>..\myCommon;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
    </ClCompile>    
  </ItemDefinitionGroup>

AdditionalIncludeDirectories is a configuration item for additional include directories, just fill in the header file path in it.

2.1 Determine the path relationship between the include directory and *.vcxproj

The include directory here refers specifically to myCommon, enter the project root directory (*.sln directory) where calcOne is located, and use tree /f to view the path relationship:

## 进入项目根目录
cd calcOne

## 查看路径关系
tree /f
Figure (6) Determine the path relationship between the include path and *.vcxproj

2.2 Fill in the include directory

    As can be seen from Figure (6), the include directory that needs to be filled is: ..\myCommon, just fill it in AdditionalIncludeDirectories, as shown in Figure (7):

Figure (7) Fill in the include path

Guess you like

Origin blog.csdn.net/sanqima/article/details/124813518