. The quoted form searches first in the local folder, then in /I specified locations, Th" />
开发者

#include - brackets vs quotes in XCode?

开发者 https://www.devze.com 2022-12-30 02:05 出处:网络
In MSVC++ #include files are searched for differently depending on whether the file is enclosed in \"\" or <>. The quoted form searches first in the local folder, then in /I specified locations, Th

In MSVC++ #include files are searched for differently depending on whether the file is enclosed in "" or <>. The quoted form searches first in the local folder, then in /I specified locations, The angle bracket form avoids the local folder.

This means, in MSVC++, its possible to have header files with the same name as runtime and SDK headers.

So, for example, I need to wrap up the windows sdk windows.h file to undefine some macro's that cause trouble. With MSVS I can just add a (optional) windows.h file to my project as long as I include it using the quoted form :-

// some .cpp file
#include "windows.h" // will include my local windows.h file

And in my windows.h, I can pull in the real one using the angle bracket form:

// my windows.h
#include <windows.h> // will load the real one
#undef ConflictingSymbol

开发者_如何学GoTrying this trick with GCC in XCode didn't work. angle bracket #includes in system header files in fact are finding my header files with similar names in my local folder structure. The MSVC system means its quite safe to have a "String.h" header file in my own folder structre. On XCode this seems to be a major no no.

Is there some way to control this search path behaviour in XCode to be more like MSVC's? Or do I just have to avoid naming any of my headers anything that might possibly conflict with a system header. Writing cross platform code and using lots of frameworks means the possibility of incidental conflicts seems large.


You should be able to do the same with gcc (I don't know how much xcode wraps things and prevent access to some features). There is a bunch of options controlling the search path (see http://gcc.gnu.org/onlinedocs/gcc-4.5.0/cpp/Search-Path.html and http://gcc.gnu.org/onlinedocs/gcc-4.5.0/cpp/Invocation.html and look for -iquote). Calling gcc with -v will give you the path specifying where the two differs.


You could try #include "./windows.h". The compiler ought to be smart enough resolve that in the local directory first.


Note that gcc supports -iquote and -isystem in addition to -I to give you more control over which directories will be searched for #includes.


I'm not sure if I understand your question correctly

Avoiding namingproblems is always better ofcourse. the "<>" are more compiler-dependent, while the """" (lol) are more projectspecific.

for example when using your compiler will look into its compiler folders (system) and when using "windows.h" it will look in you projectfolder(s)

if a include "windows.h" is not working, check your makefile or projectsettings

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号