Solved

Can not include header file

Posted on 2003-11-03
14
264 Views
Last Modified: 2013-11-18
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.
0
Comment
Question by:expertyasin
  • 3
  • 3
  • 3
  • +2
14 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9670044
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)
0
 

Author Comment

by:expertyasin
ID: 9670096
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
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9670106
try #include "layout\\test.h"

windows is trial and error for me ;o)
0
 

Author Comment

by:expertyasin
ID: 9670119
I have tried that also . It is not working ;o(


0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 9670137
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
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Accepted Solution

by:
Ajar earned 20 total points
ID: 9670193
expertyasin ...if you are using vc++ compiler then it should not idealy complain about the slash  that is  / or \ in the include path.


include the file the normal way like

#include <layout/test.h>


and in the VC++ menu   Tools > options > includepath  add the parent directory of  layout.



0
 
LVL 15

Expert Comment

by:efn
ID: 9672421
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
0
 

Expert Comment

by:rmani13
ID: 9674445
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
0
 

Author Comment

by:expertyasin
ID: 9675602
Got it .Thanks lot guys.
0
 

Expert Comment

by:rmani13
ID: 9679312
Probably you can close this if it worked.

Thanks.
Mani
0
 

Expert Comment

by:rmani13
ID: 10524135
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
 
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
An API detour question 7 79
Specific format 21 181
Create associate webpages / websites 3 66
IIS Log files on Exchange 2013 server 6 75
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now