PDA

View Full Version : Including Libraries respectively Header Files in the CORRECT Order



Nathalia
6th March 2015, 12:45
Dear Community,

I had issues to include all my needed header files since they were in many different sub folders. However, I added them now manually. The drawback is that now a lot of "ISO C++ forbids declaration of 'desc' with no type [-fpermissive]" errors (around 130) occur. I think the reason is that the header files are included in wrong order, is that correct? So is there any way to find out which order is the correct/right one?


Thank you.:)

Nathi

wysota
6th March 2015, 13:24
You have to resolve conflicts manually by reordering the statements in your code. However since this thread is a continuation of the other thread of yours then your approach is inherently broken and you might not be able to resolve such conflicts at all.

Nevertheless I don't think the error you are getting is related to the order of includes. More likely a conflict between a define and a datatype name, a missing include or simply an error in your code (missing type declaration for the variable).

Consider the following directory structure:

dir1/file1.h
dir1/file2.h

dir2/file1.h
dir2/file2.h

Your code:

#include "file1.h"
#include "file2.h"

With "INCLUDEPATH += dir1 dir2" you will include dir1/file1.h and dir1/file2.h.
With "INCLUDEPATH += dir2 dir1" you will include dir2/file1.h and dir2/file2.h.

Now try writing code which includes dir1/file1.h and dir2/file2.h without using full paths to the include files (which you claim to be insane in the other thread).
To make things harder have another file in your project where you want to include dir2/file1.h and dir1/file2.h

Nathalia
6th March 2015, 16:03
Oh okay. Well thanks for this very illustrative explanation - this helps me to comprehend also my other thread and well I still think its insane that in 2015 it is still required to do that manually but well... So then I will take my weekend to work on including all the headers I need at the correct order.

Greez
Nathi

wysota
6th March 2015, 16:27
I still think its insane that in 2015 it is still required to do that manually but well...

I understand that if you open a commandline (e.g. cmd) on your computer and enter a name of a file then your command line searches your whole computer and all network volumes and executes that file and it does it fast and knows well which binary to execute if you have multiple files with the same name. It's year 2015 and my shell still searches only the directories set in PATH.