Link to home
Start Free TrialLog in
Avatar of expertyasin
expertyasin

asked on

Can not include header file

Hi,

Iam bit new to C . I built a project in Visual C++,namely "Test" .

Then i created a folder under "Header Files",namely "layout" . Under this layout folder
i added  "test.h" header file .

Then I added a sample.c file under "Source files" .This c file just tries to include the "test.h" header file .

So in C file , i put the syntax as #include "layout/test.h" .

When i save & compile this c file , its giving the following error.


fatal error C1083: Cannot open include file: 'layout/test.h': No such file or directory
Error executing Test.exe.

Any help highly appreciated.
Avatar of sunnycoder
sunnycoder
Flag of India image

Hi expertyasin,

directory separator in windows is \
better way to use header files is to create one in the working directory and #include using " "
creating header files along with the standard library hearder files in not a recommended approach

Cheers!
Sunny:o)
Avatar of expertyasin
expertyasin

ASKER

Hi Sunny,

Thanx for ur quick response .

I used directory separator also. But it is not working .

But if i move the header file from the sub folder  , and if i use  #include "test.h", its working fine .

But if i use a subfolder (layout) , and syntax #include "layout\test.h"  
then its not working .

Regards,
Yasin
try #include "layout\\test.h"

windows is trial and error for me ;o)
I have tried that also . It is not working ;o(


try with <> in place of " "
(since it is in library headers, <> should have been used for efficiency)

else try specifying the complete file path name
ASKER CERTIFIED SOLUTION
Avatar of Ajar
Ajar

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
When you create a layout folder in the FileView, that is just a way to organize files in that view.  It does not create a directory in the file system on the disk and the compiler pays no attention to it when searching for the file.  So if the file is yourProject\test.h in the file system, you should refer to it in the #include directive as "test.h" regardless of where it is in the FileView.

Conversely, if you really want to #include it as "layout\test.h", then create a layout directory in the file system, put the header file in there, and then add it to the project.  But understand that you will then have to refer to it as "layout\test.h" no matter where it appears in the FileView.

--efn
Assume that the directory structure is like this for the files you have created.
folder\Include files\layout\test.h
folder\source files\sample.c

In this case you have to give the include statement like the following
#include <..\Include Files\layout\test.h>
or the complete path of the header file.

Hope this helps.

Mani
Got it .Thanks lot guys.
Probably you can close this if it worked.

Thanks.
Mani
Why the following comment from me can't be accepted?


Comment from rmani13
Date: 11/03/2003 02:16PM PST
 Your Comment  
Assume that the directory structure is like this for the files you have created.
folder\Include files\layout\test.h
folder\source files\sample.c

In this case you have to give the include statement like the following
#include <..\Include Files\layout\test.h>
or the complete path of the header file.

Hope this helps.

Mani