0

In my Xcode project I added a new target for unit testing (using google C++_ testing framework). I created a new directory (for e.g. /unittest/myproject/) where I copied the source(.h/.cpp) files and did some modification (for e.g. made protected methods to public) for testing purpose and added to unit test target.

But when I Includes a .h files main.cpp it is referring to original file instead of file which is inside /unittest/myproject/. Also I have set the header search path to "$(SRCROOT)/../../unittest/myproject" but still main.cpp refers to original file (Command+click takes to original file). Can anyone please suggest what I am missing? Xcode Version 4.6.3

jww
  • 97,681
  • 90
  • 411
  • 885
Akhil Shrivastav
  • 427
  • 3
  • 13
  • You're gonna want to temporarily remove the original file from your /usr/local/include or whatever default search path it is in, as those search paths are included before your own. – Francisco Aguilera Apr 20 '15 at 11:41
  • Possible duplicate of [How to set include path in xcode project](http://stackoverflow.com/questions/14134064/how-to-set-include-path-in-xcode-project) – jww Apr 20 '15 at 12:12

1 Answers1

0

Problematic header is definitely present in another directory, that is seen by XCode as include path.

Such directory may be, for example:

  • /usr/include
  • /usr/local/include

and others, depending on your environment settings.

I would suggest you to search for all files with such name and see, what directories will be returned by system.

Then, you should either remove this file[s] (if it is not used anymore) or remove its parent directory from include path set in XCode. That should help.



One more thing:

You should also check, what type of include do you use for this file:

  • using quotes: #include "header.h"
  • using brackets: #include <header.h>

It's compiler-dependent, but generally, quote-style prioritizes headers, that are present in the same directory as file containing #include statement.

From the specification:

A preprocessing directive of the form

# include <h-char-sequence> new-line

searches a sequence of implementation-defined places for a header identified uniquely by the specified sequence between the < and > delimiters, and causes the replacement of that directive by the entire contents of the header. How the places are specified or the header identified is implementation-defined.

A preprocessing directive of the form

# include "q-char-sequence" new-line

causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delimiters. The named source file is searched for in an implementation-defined manner. If this search is not supported, or if the search fails, the directive is reprocessed as if it read

# include <h-char-sequence> new-line

with the identical contained sequence (including > characters, if any) from the original directive.

Mateusz Grzejek
  • 11,698
  • 3
  • 32
  • 49