Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<string.h> conflicting with my own String.h

I have a project that was compiling ok within g++(I can't see the version right now) and now on xCode it is not.
I think that I got the problem now... I have a String.h file in my project and it seems tha the xCode compiler(that is gcc) is trying to add my own string file from the < cstring >... I am not sure of it, but take a look at this picture
http://www.jode.com.br/Joe/xCode1.png

from what it looks like, it is including my own instead of the system file, I was wondering... shouldn't #include < file > be a system include? because of the < > ? and shouldn't the system include a file within its own path and not the original path of my application?
As I said, I am not sure if this is what happening because I am just migrating to osx these past 2 days...
I was going to change my class and file name to not conflict, so it would work, if this is really the problem, but I was wondering, there should be another way to do this, because now my project isn't that big so I can do this in some time, but what if the project was bigger? it would be dificult to change all includes and class names...

Any help is appreciated

Thanks,
Jonathan

like image 557
Jonathan Avatar asked Jun 26 '10 18:06

Jonathan


1 Answers

Two things you're running into:

  1. As noted above, the filesystem on Mac OS is case-insensitive unless you specifically set up your filesystem to be case-sensitive.
  2. gcc does not distinguish all that much between local and system header include paths. When you specify a directory to be added to the path via -I, that directory will be used to locate both local and system includes. Only when you use -iquote or -I- does a directory get skipped for locating system includes. Further, the builtin "system include" directories on the compiler's search path are always searched for local includes.
    • Note that the current directory is used for local but not system includes. In this case, I believe it's picking up String.h because the project settings explicitly add the top-level project directory to the include path.

The workaround I would suggest, rather than renaming your includes, is to put your utilities into a directory whose name is unique for your project, and specify that directory in your include directive. For example:

#include "Josk/String.h"

and make sure Josk/ itself isn't in your include search path. This way you aren't stuck with an awkward rename, though you may have to shuffle some files around in your project. You may also need to edit your project settings to make sure the parent directory of that utility directory is in your include path.

Another possibility to try is, if you see the top-level project directory added to your project's include path, remove it. This ought to keep items in your top-level project directory from being searched for system includes.

Finally, you may also be able to avoid this problem in this specific case by changing the case sensitivity of your file system. This can break some Mac applications, though, so research the issue before you embark on this – or pick a volume that nothing else is using.

like image 134
Owen S. Avatar answered Sep 28 '22 03:09

Owen S.