Jump to content

  • Log In with Google      Sign In   
  • Create Account

c++ include define DIR


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 jeff8j   Members   -  Reputation: 749

Like
0Likes
Like

Posted 15 May 2013 - 07:10 PM

I am trying to set a directory to a define like #define DIR "/dir"

and use that to include a bunch of files like #include DIR+"header.h"

this is not working its giving me #include expects "FILENAME" or <FILENAME>

is there some way of making this work or does the preprocessor not work like this?

Firefox youtube video and audio downloader MP3 MP4 OGG WEBM

https://addons.mozilla.org/en-US/firefox/addon/simple-youtube-converter/


Sponsor:

#2 fastcall22   Crossbones+   -  Reputation: 4334

Like
0Likes
Like

Posted 15 May 2013 - 07:32 PM

No. The preprocessor does not work like this.


Why do you need a preprocessor variable to define a directory?
c3RhdGljIGNoYXIgeW91cl9tb21bMVVMTCA8PCA2NF07CnNwcmludGYoeW91cl9tb20sICJpcyBmYXQiKTs=

#3 jeff8j   Members   -  Reputation: 749

Like
0Likes
Like

Posted 15 May 2013 - 07:35 PM

Hmm that sucks theres so much it can do you would think it could do that somehow.

 

I have 37 header files I want to include that are in a versioned directory ie library-0.4.1/

I could rename the folder to just library but I was wanting to keep multiple versions to change them easily.

When 0.4.2 comes out I could simply change dir defined path to library-0.4.2 and if I dont like it or it doesnt pass the tests I could revert easily


Firefox youtube video and audio downloader MP3 MP4 OGG WEBM

https://addons.mozilla.org/en-US/firefox/addon/simple-youtube-converter/


#4 0r0d   Members   -  Reputation: 819

Like
1Likes
Like

Posted 15 May 2013 - 08:07 PM

Hmm that sucks theres so much it can do you would think it could do that somehow.

 

I have 37 header files I want to include that are in a versioned directory ie library-0.4.1/

I could rename the folder to just library but I was wanting to keep multiple versions to change them easily.

When 0.4.2 comes out I could simply change dir defined path to library-0.4.2 and if I dont like it or it doesnt pass the tests I could revert easily

Add a path to that library in the "Additional Include Directories" (for Visual Studio), or whatever is the same thing in your IDE.  Then you can include files from that directory like this:

 

#include <subfolder/file.h>  // where "subfolder" is a folder inside whatever path you told the compiler about

 

This will give you exactly what you want.


Edited by 0r0d, 15 May 2013 - 08:10 PM.


#5 Servant of the Lord   Crossbones+   -  Reputation: 19568

Like
1Likes
Like

Posted 15 May 2013 - 08:28 PM

You could do this:

 

#define HEADER(path) "/dir/" ## path
 
#include HEADER("my path/file.h")

 

But really, it's better to just specify "/dir/" manually so as to not confuse others reading your code (including yourself in the future).

 

If "/dir/" is long, then make sure you specify your compiler's include paths properly. In gcc and MinGW, this is: "gcc -I <include path>" (That -I is a uppercase 'i'). You can specify multiple include paths to search.


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#6 Trienco   Crossbones+   -  Reputation: 2173

Like
1Likes
Like

Posted 15 May 2013 - 10:03 PM

As mentioned above, there's a whole bunch of methods that are all better than abusing the preprocessor for this.

 

a) If stuff is versioned, why not use a version control system instead of folder names?

b) Failing that, the -I option exists for exactly that kind of thing (ie. it belongs in your project settings or Makefile, not the actual source code)

c) Use a symlink that points to whatever version you want to use (yes, Windows finally has them too)


f@dzhttp://festini.device-zero.de

#7 jeff8j   Members   -  Reputation: 749

Like
0Likes
Like

Posted 15 May 2013 - 10:18 PM

@0r0d that would do it I can set the paths in gcc but not quite the solution I was hoping for

 

@Servant of the Lord Thats exactly what I was looking for although its giving me an error im still messing with it to figure it out.

 

@Trienco

a. The local versions differ from the actual version granted I could setup my own version control but I dont want other parts of the program to revert just this single part I could setup 2 one for the library and one for the program but thats just asking for issues and I dont want to have to manage anything a static folder is simple and already exists on my machine/in the source for any machine.

b. Yes I get that just like 0r0d but its much easier for me to work on a certain section that try to coordinate a compile time option across developers.

c. That would work and would be in my specific section (all compilation is on a linux machine so no worries im not familiar with symlinks in windows havent compiled or done anything other than games on it in a long time) I may fallback to this if I cant get Servants way to work.


Firefox youtube video and audio downloader MP3 MP4 OGG WEBM

https://addons.mozilla.org/en-US/firefox/addon/simple-youtube-converter/





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS