views:

172

answers:

4

Given this directory tree:

src/MyLibrary/MyHeader.h
src/file.cpp

file.cpp:

#include "mylibrary/myheader.h"
...

Compiling file.cpp works with VS, fails in gcc.

  • What does the standard say?
  • If the path is case sensitive, why is this wise?
  • What's the best practice, keep all file/folder names lowercase and thus do the same when including?

Thanks.

+1  A: 

Its not C++ standard, its the Linux way, where all path names are case sensitive. The best practice is too chose whatever file name you want ( mostly lowercase) and use the same case in the include directive. Also always use relative file paths.

Priyank Bolia
+13  A: 

The case sensitivity depends on the Operating System. Windows is not case sensitive. Linux is.

EDIT:

Actually, as observed by Martin York's comment, the case sensitivity depends on the file system. By default Windows uses a case insensitive file system, while Linux uses a case sensitive one. For whoever is interested to know which file systems are case sensitive and which aren't, there is a comprehensive list on Wikipedia: Comparison of file name limitations.

Daniel Vassallo
Actually its more related to the file system used rather tahn the OS. The default is as defined as above. But on Linux there is a greater veriety of file system to choose from some of which are not case sensative.
Martin York
@Martin: Yes you're right. Thank you for the accurate observation.
Daniel Vassallo
+3  A: 

Windows says no, unix says yes,

But you should mind the correct case for multiplatformness and readability.

Most development conventions will suggest using all-lowercase file names.

Pavel Radzivilovsky
A: 

Another point to remember is the path separator character. Even though Visual Studio (and other Windows IDEs I'm sure) will accept either '/' or '\', you should always use '/' within an include path for portability.

Dan
For better portability, such as moving sources files, paths should not be in source code but given to the compiler. If header files move, then all the code that references them by path must be changed and regression tested!
Thomas Matthews