views:

178

answers:

3

Is there a way to specify include directories in the code, perhaps via a #pragma?

I have my project setup as "src/" and "include/" folders. I am trying to compile in Visual Studio 2010, but I don't want to set it up in the project settings.

Is there another way to allow it to compile instead of having to specify the include as

#include ../include/ss.h
+6  A: 

The Correct(tm) way to specify search directories is with compiler flags. In Visual Studio you do this by playing with the project settings, or its compiler's /I commandline parameter.

wilhelmtell
It is indeed `/I [path]` on the Windows command line.
MSalters
Thanks for confirming that. I didn't have access to a Visual C++ compiler. :-S
wilhelmtell
A: 

In Visual studio, you can also define include folders by setting them via Options/File Locations. Then you don't need to repeat them in every project setting. (Assuming that's what you're after). It is a bit weird to define absolute paths in source code, you'll never know from which folder/drive a build is run.

jdv
A: 
0A0D
String literal concatenation happens by the compiler, but include files are handled by the preprocessor. You're too late.
MSalters
@MSalters: My wording may have been wrong but aren't they both pre-processor directives?
0A0D
No, they're not. See http://stackoverflow.com/questions/1476892/ for details, especially pmg's quote from C99 (C++ is essentially the same). Preprocessing directives (such as `#include`) are handled by step 4; string concatenation is step 6.
MSalters
@MSalters: Thanks for pointing me in the right direction.. all these years I never had it presented this way. Thanks for the information - you enlightened me!
0A0D