Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I want to use a library in my client application. For that I need to include path of header files of library functions/classes in my client application.
But the problem is that I dont have all header file in directory. There are subdirectories also which contains header file and for that I need to explicitly add the path of all subdirectories in recursive way. There is too much manual work.
Can anyone please tell me is there any way to add all subdirectories in client application by some tool or any otherway?

Thanks in advance
Posted
Comments
Andreas Gieriet 12-Sep-13 13:38pm    
This is tiny work if you put away your IDE for a moment and learn a bit working on the shell ;-)
Cheers
Andi
pasztorpisti 15-Sep-13 16:25pm    
Good advice. After understanding "manual compilation" its easier to find out what kind of commands are issued by a complex IDE.

Answer two to this Stack Overflow question: "How to include sub-directories in Visual Studio?"[^] shows a workaround for Visual Studio.
 
Share this answer
 
Comments
H.Brydon 14-Sep-13 21:30pm    
That's not really a workaround - that is the right way to do it.
CPallini 15-Sep-13 5:26am    
Thank you. I was not sure this was the only way to do it.
Andreas Gieriet 15-Sep-13 9:58am    
That's the right way.
I doubt that the OP really has to add more than one (or a few) base include directories...
Cheers
Andi
Andreas Gieriet 15-Sep-13 9:59am    
My 5!
That's the right solution.
Cheers
Andi
you can add "include directories" in the project settings.
 
Share this answer
 
Comments
Rahul from Poona 12-Sep-13 13:08pm    
I am doing the same. But explicitly I have add a number of sub directories and that is the manual work I have to do.
My question is that is there a way to include all subdirectories of a folder without explicitly including them.
nv3 12-Sep-13 13:14pm    
No - not that I know of. How many directories in total do you have to include?
Rahul from Poona 12-Sep-13 13:17pm    
There are 48 sub directories
nv3 12-Sep-13 14:35pm    
So in the worst case you have to type 48 include statements -- so what? But this worst case will probably not happen, except this is an extremely bad organized project. Typically, you include one (or at most a few) header files and they will include everything else for you, which might be needed. So just find out which headers you have to include.
KarstenK 16-Sep-13 4:20am    
consider cleaning up your mess ;-)
This looks like a strange 3rd party library where you have to include header files from multiple subdirectories.
Are you sure you need to do so?

If yes, and if you are working on a *nix environment, you may call find * -type d | sed 's/^\(.*\)$/-I\1 \\/g' > includedirs.txt and then take that list and paste it (after pruning(?)) into your Makefile's CPPFLAGS setting.

If you are working on M$ environment you may use cmd.exe or powershell to to get all directories and then produce the respective -IXXX entries e.g. in a text editor.

Cheers
Andi
 
Share this answer
 
I used to work at a site that used build areas like that. To properly build the source, make sure that each project has added $(SolutionDir) to the include path, and then assume that all parts of the build process are rooted where the solution directory lives. Build your class and project hierarchy and build everything as if looking down from the directory where the solution lives.

Use '#include <blah.h>' include syntax instead of '#include "blah.h"'. For headers that are a level below the solution directory, add the directory hierarchy to the #include statement. For example:
C++
#include <stdafx.h>
#include <sub1\head1.h>
#include <sub2\head2.h>
#include <oh\what\a\deep\structure\blahblah.h>

You don't want to monkey with the header include directives to make all subdirectories into a flat space. If you have 2 directories with "myclass.h" for example you won't be able to distinguish them properly (or imagine the trouble with 14 copies of stdafx.h).
 
Share this answer
 
v3
Comments
pasztorpisti 15-Sep-13 16:29pm    
I'm not sure about this but as if I read somewhere that #include <something> is to include system includes (and libs that are installed into your build environment outside the solution) while #include "something" is to include local stuff (residing inside the solution). Of course this is not something written into stone.
H.Brydon 15-Sep-13 16:51pm    
No, (at least for the Microsoft compiler) - use of the quoted version uses an arguably defective search path depending on essentially cached info (which can have bizarre header dependencies that are impossible to debug). Use of the angle bracket version, the search path is unambiguous.

Check out Microsoft's rules at http://msdn.microsoft.com/en-us/library/36k2cdd4.aspx

I don't know if this is Microsoft specific or not, so I don't know the rules for other compilers.
pasztorpisti 15-Sep-13 16:59pm    
Nice page, I didn't know that it exists. In a painful series of experiments (with VC++ and g++) we found out that one thing that is different in g++ when it comes to quoted includes is that g++ doesn't do the second point from the list: "In the directories of any previously opened include files in the reverse order in which they were opened. The search starts from the directory of the include file that was opened last and continues through the directory of the include file that was opened first." g++ doesnt do this, it takes into account only the last opened include file but doesn't go back on the "stack". Just because I was curious I was searching with google for the difference between the two includes: http://stackoverflow.com/questions/3162030/difference-between-angle-bracket-and-double-quotes-while-including-heade. The answer seems to support my memories, generally angle brackets are (were) used to include from system directories.
H.Brydon 15-Sep-13 17:29pm    
The SO page just seems to say to use angle brackets for system headers without saying why. At my company we had a build system that (I think correctly) required all includes to use angle bracket syntax.

Suppose you (stupidly) added a file called "windows.h" to your local directory and used quote syntax. That would break a lot of things. Other more subtle examples could be determined with the same principle...
pasztorpisti 15-Sep-13 17:36pm    
The most important thing is in the last two sentences. Of course the convention of using angle brackets isn't necessarily followed by compilers and the same is true for people who usually use an approach that works on their platform with their devenv. But that is just one approach from the many. Usually its a bad thing if you can do the same thing in many ways. The compilation model of C++ sucks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900