How can I ignore the header file in the same directory where source code is, which includes the header and use the other header in different path

성진 김 1 Reputation point
2021-06-09T07:19:54.61+00:00

At first, my project tree is as below

project/main.c
project/Test.h
project/Test/Test.h

In "main.c",

include "Test.h"

Currently, "Test.h" in "main.c" refers to project/Test.h because Visual Studio finds the included header first in the same directory where source code including the header is.
I want to fix that "Test.h" in "main.c" refers to project/Test/Test.h without any modification of source code.

Is there any solution for this?

Community Center | Not monitored
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Anna Xiu-MSFT 31,056 Reputation points Microsoft External Staff
    2021-06-10T10:15:42.873+00:00

    Hi @성진 김 ,

    Welcome to Microsoft Q&A!

    If you don’t want to edit your code, you can right click on your project in the Solution Explorer > choose “Properties" > VC++ Directories > Include Directories > Add your include directories.

    Sincerely,
    Anna

    • If the answer is helpful, please click "Accept Answer" and upvote it.
      Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    0 comments No comments

  2. RLWA32 49,536 Reputation points
    2021-06-10T21:07:41.297+00:00

    To avoid having the preprocessor search for included headers in the same location as the source file the #include directive should use angle brackets instead of quotations. The details of how the preprocessor searches are discussed in hash-include-directive-c-cpp

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.