By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,148 Members | 1,339 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,148 IT Pros & Developers. It's quick & easy.

C++ includes problem

P: 18
Hi all,
I have to include files from different projects in the solution file. I mean I have a temp.cpp in the project Test1 and work.h,work.cpp in the project Test 2 in my visual studio solution.

The structure is -
Test1\temp.cpp
Test2\work.h
Test2\work.cpp

If I have to include work.h in temp.cpp, I'm using the following code

#include "../Test2/work.h"

I'm getting the following error -
Error 1 fatal error C1083: Cannot open include file: '../Test2/work.h': No such file or directory c:\documents and settings\santosh singh\my documents\visual studio 2005\projects\mySolution\Test1\temp.cpp 13

I tried giving all possible combinations -

#include "..\Test2\work.h"
#include "..//Test2//work.h"
#include "..\\Test2\\work.h"

it did'nt work. Please help me out.


Thanks in advance.

Regards,
SC
Mar 17 '07 #1
Share this Question
Share on Google+
7 Replies


Expert 100+
P: 1,510
Expand|Select|Wrap|Line Numbers
  1. #include "..\\Test2\\work.h"
  2.  
should work if subdirectories Test1 and Test2 are in the same directory?
Mar 17 '07 #2

P: 18
Hi,
Thanks for the reply.

Yes, Test1 and Test2 are in the same parent directory.

mySolution\Test1
mySolution\Test2

I have to include files from Test2 in Test1

Thanks again,
SC

Expand|Select|Wrap|Line Numbers
  1. #include "..\\Test2\\work.h"
  2.  
should work if subdirectories Test1 and Test2 are in the same directory?
Mar 17 '07 #3

Expert 100+
P: 1,510
Hi,
Thanks for the reply.

Yes, Test1 and Test2 are in the same parent directory.

mySolution\Test1
mySolution\Test2

I have to include files from Test2 in Test1

Thanks again,
SC
in that case when compiling a file in Test1
Expand|Select|Wrap|Line Numbers
  1. #include "..\\Test2\\work.h"
should include file work.h in Test2

have a read thru
http://msdn2.microsoft.com/en-us/library/36k2cdd4(VS.80).aspx
Mar 17 '07 #4

P: 18
Hi,
Thanks for the reference. I went through it. I'm giving the fully qualified name of the include file as #include "..\\Test2\\work.h"

I guess my problem is with the syntax.

Please let me know if the syntax is right as I couldn't find much help elsewhere.

Thanks again,
SC


in that case when compiling a file in Test1
Expand|Select|Wrap|Line Numbers
  1. #include "..\\Test2\\work.h"
should include file work.h in Test2

have a read thru
http://msdn2.microsoft.com/en-us/library/36k2cdd4(VS.80).aspx
Mar 17 '07 #5

DeMan
100+
P: 1,806
I have occasionally encountered similar problems when using an IDE (rather than a command line compiler). There is usually an option in the menus (Project Options or similar) where you can specify the directories where the compiler will look for code. To use the same path you have, you can make sure that "mySolution/Test1" is in the path, alternatively, If you add "mySolution/Test2" to the path, you can simply #include "work.h".

If you are working from a command line, make sure the path includes "." (or "./")
Mar 18 '07 #6

Expert 100+
P: 1,510
Hi,
Thanks for the reference. I went through it. I'm giving the fully qualified name of the include file as #include "..\\Test2\\work.h"

I guess my problem is with the syntax.

Please let me know if the syntax is right as I couldn't find much help elsewhere.

Thanks again,
SC
the syntax looks fine and similar code works on my machine OK with gcc.
I guess it could be a problem with Visual Studio which I don't use. DeMan made some suggestions - try them out.
Can you compile from the command line ? or try with a different compiler?
Mar 18 '07 #7

P: 18
Hi,
I figured out what the problem was. In VC++, the compiler takes the debug directory as the reference. So, I just have to give ../../file.h.

Thanks a lot for your support.

SC


the syntax looks fine and similar code works on my machine OK with gcc.
I guess it could be a problem with Visual Studio which I don't use. DeMan made some suggestions - try them out.
Can you compile from the command line ? or try with a different compiler?
Mar 24 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.