Make include statement case insensitive
-
Hi,
I've had to move my projects to a different folder. Now when I try to build the projects Qt Creator complains when the include statement has the wrong case. So
#include "dbPanelSessionabstract.h"
won't work but
#include "dbpanelsessionabstract.h"
does.I understand that technically this is probably correct because the file itself is lower case but this has never been an issue so far and if I have to change everything I'm going to die.
Is there a way to make Qt Creator ignore case sensitivity here? I'm on Linux. Thanks.
Best wishes,
Angela -
This is not a QtCreator problem - it's simply wrong on case-sensitive filesystems (like most filesystems on linux). So fix your include statement or rename your file.
-
-
@angela2016
As @Christian-Ehrlicher has said this is C++#include
behaviour (and everything else) on a case-sensitive file system, like Linux (but not Windows) usually is.because the file itself is lower case but this has never been an issue so far
Then this would never have worked as-is on a Linux file system. Go back and look at where you copied the files from. Is it mixed-case there or lower-case only? You are likely in one of three situations:
- The original is a Linux file system and the files are mixed-case. Then your Linux-to-Linux copy should retain case. If you claim this is the situation but the mixed-case is not retained then something is wrong in how you copy.
- The original is, say, a Windows file system and the files are mixed-case there. Then go find why your copy changes to lower-case and fix that.
- The original is, say, Windows and the files there are all lower-case. It will compile under Windows without you noticing that the cases of the files and the
#include
s differ but will never work under Linux. Since the#include
code expects the filenames to be in mixed-case there is something wrong about how you originally got the files into Windows in the first place, they should always have been mixed-case even under Windows.
-
@JonB I copied the files from a USB stick (FAT) to a hard disc (NTFS). The names of the files weren't changed (all lower case). The includes were sometimes mix cased. I used to compile on both Windows and Linux, but for a year or so only on Linux and I have completely rebuilt the project multiple times.
I have now written another program to help me fix the file names, but I'm still curious as to why compiling on Linux worked before.
-
@angela2016
FAT is what I call Windows, i.e. it's for Windows and is case-insensitive. That means the file system with somefile.h
(your all lower case) file will happily supply that when asked for it in any case, so e.g.#include "FiLe.h"
(your mixed case) will find it. If you compiled your source on that file system format files there would match any case in the source includes.The moment you copy that to NTFS the situation changes. NTFS, unlike FAT, is case-sensitive. However, Windows effectively treats it as case-insensitive, in that when it creates/opens files Windows does work to make creating "FiLe.h" overwrite an existing "file.h" and opening "FiLe.h" will open an existing "file.h". So it is the Windows OS, not the NTFS file system, which effectively enforces case-insensitivity. https://en.wikipedia.org/wiki/Case_sensitivity :
the FAT file systems became case-preserving as an extension of supporting long filenames.[8] Later Windows file systems such as NTFS are internally case-sensitive, and a readme.txt and a Readme.txt can coexist in the same directory. However, for practical purposes filenames behave as case-insensitive as far as users and most software are concerned.[9] This can cause problems for developers or software coming from Unix-like environments, similar to the problems with macOS case-insensitive file systems.
But when you access NTFS from Linux, a case-sensitive OS, Linux treats
FiLe.h
amdfile.h
as quite distinct, as it would on any other file system such as ext4. So then#include "FiLe.h"
will fail if on NTFS the file isfile.h
.TBH I regard accessing FAT from Linux as "inappropriate", and could cause problems. Accessing NTFS from Linux is OK if you really have to BUT not if you mix that with writing to it from Windows.
So.... Your original problem is that you have source code with
#include "dbPanelSessionabstract.h"
but the file on your original FAT is, apparently,dbpanelsessionabstract.h
. This will go wrong once you copy it off FAT. The issue is how did it ever come to bedbpanelsessionabstract.h
in the first place? This is wrong. Presumably the author of the.cpp
s had the file on disk asdbPanelSessionabstract.h
at the time they wrote the#include
, whatever file system it was on. Some copy changed that to all lower-case, and that is where the problem stems from.Summary: Your code would compile as-is against a FAT file system. Now that you are using NTFS (or ext4) with Linux you either have to change (or re-copy) the files on disk to match the
#include
mixed-case or you have to change all the#include
lines to match the case on disk. -