Jump to content
Sign in to follow this  
[frl]myke

#include statement for file in parent folder?

Recommended Posts

Ok, first of all: yes, i've searched before posting and yes, there were a few (old) threads about it but none of them had a answer in it.

It is about the include statement. Let's assume the following folder structure:

P:
|- my_main_addon_folder
   |- a_subfolder

Now there is a config.cpp in the my_main_addon_folder and also a file named basicdefines.h.

Obviously, in the config i can use this:

#include "basicdefines.h"

works as expected, no problem so far.

now, in the subfolder there is also a config.cpp in which i would like to include the basicdefines.h file aswell.

Ok, i could simply put a copy of the basicdefines.h file in the subfolder and use the above #include statement. But somehow this would put the existence of such a file ad absurdum. If i want to change one of the defines or add some more, i would have to edit 2 files instead of just one (speaking of the addon i'm working, the subfolder count is >50).

So i've tried this:

#include "\my_main_addon_folder\basicdefines.h"

Well, if this would have worked, i wouldn't be writing this story here, wouldn't i?

So my question: is it possible (and if yes, how?) to include a file into a config which is located one folder above?

Share this post


Link to post
Share on other sites
Myke;2120271']So my question: is it possible (and if yes' date=' how?) to include a file into a config which is located one folder above?[/quote']

Nope. At least not using standard methods.

Probably the easiest way is for you to download and use Link Shell Extension.

Once installed and while in Windows Explorer just go find the file you want to include and right-click on it. Select 'Pick Link source' from the context menu. Then navigate to the folder where your config.cpp is and right-click in some blank space and select 'Drop Hard Link' from the context menu.

Then in your config.cpp just have #include "yourfile.hpp".

The good thing about this is the 'file' that is then sitting in your local folder is not a duplicate or a copy of the original it's a symbolic LINK to the one and only original file. If you open the link file you're actually opening the original file.

There is another more complicated method I sometimes employ where one doesn't use symbolic links created with Link Shell Extension. But it's more complicated. However, it does mean you can use include statements like... #include "..\..\common.hpp". If your interested in that method then I'll detail it for you but it is more complicated to manage.

I'd recommend you use the above symbolic linking method with Link Shell Extension.

Share this post


Link to post
Share on other sites

Synide, this Link Shell Extension does the trick perfectly, thank you. It prevents me of having 56 versions of the same file (literally) keeping up to the same content. Really appreciate your help.

Share this post


Link to post
Share on other sites

i would call that a nasty hack. what would happen if the same pbo is run in linux? i wonder why relative paths are not working in this case. furthermore, preprocessor can not tweak string in include. hmmm. like always, bistudio wiki documentation is a little bit of a joke: https://community.bistudio.com/wiki/PreProcessor_Commands. There is a link in the bottom pointing to external pdf. That pdf is wrong in stating that relative include paths would work. In two words, they wont.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×