Solved

c language help - file paths

Posted on 2014-03-02
7
140 Views
Last Modified: 2015-05-28
Hi,

I have code for reference to header files. But, I get below error:

No such file or directory
compilation terminated.

Code is like below:

#include <header/abc-logging.h>

#include <header2/soap-log.h>

Open in new window


The path of files is like this:

home>code>examples>logexample   // this is source code path while in source code header like above are defined

The path for "header" folder is  home>header and for header2 , path is home>header2.

Is it wrong, I tried to put it in different paths but I always get error for file not found. Is there permission issues?

Please guide.

Thanks
0
Comment
Question by:Johny12345
7 Comments
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 39898566
If you are using gcc or similar, compile with -Ihome or set CPATH
0
 

Author Comment

by:Johny12345
ID: 39898604
How to do it? I am using Terminal in ubuntu
0
 
LVL 84

Expert Comment

by:ozo
ID: 39898609
cc -I/home /home/code/examples/logexample.c
0
 
LVL 12

Expert Comment

by:satsumo
ID: 39901496
Given the file layout you describe this should work:

#include "../../header/abc-logging.h"

#include "../../header2/soap-log.h"
But that is a more inflexible way to do it. It requires the header files to be in a specific location relative to the source file. The method that ozo is suggesting is better. It adds the directory containing the header to the include search path so that the compiler can find them.

In C #include<foo.h> means find foo.h in the include search path (or a relative path) #include "foo.h" means find foo.h in the current directory (or a relative path).
0
 
LVL 33

Expert Comment

by:sarabande
ID: 39902955
It requires the header files to be in a specific location relative to the source file. The method that ozo is suggesting is better. It adds the directory containing the header to the include search path so that the compiler can find them.
actually both concepts normally would be used for a c or c++ project.

if the header folders belong to the one project they should be relative to the folder where the sources of the project are. the home folder doesn't make so much sense for this case. typically they would be in the same folder as the sources to compile. if it is too many files you may have two folders 'header' and 'source' below the project folder.

if the header files should be used by multiple projects you should put the folders below a root folder that is above all the project folders. it is also good practice to have a 'common' folder, then. you would use the common folder either by  

#include "../../common/header/xx.h"

or better add the absolute path to the common file to 'include' environment variable (for example by setting and exporting the 'include' variable in the .bashprofile). if the folder could be found by environment variable you could do the include statements like

#include <xx.h>

note, the <> brackets which is a syntax to indicate include files being stored at known include folders. most compilers do not (no longer) be sensitive to the kind of brackets but it is still good programming if you do it in your sources.

headers which come from 3rd libraries always should be added to folders that were known by include variable or by -I compiler option.

Sara
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Which checksum is this? 7 139
Inorder binary search tree 5 158
Detect CR LF to each line 12 152
How to copy documents folder to network folder automatically as backup? 15 83
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

914 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

22 Experts available now in Live!

Get 1:1 Help Now