Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

c language help - file paths

Posted on 2014-03-02
7
Medium Priority
?
160 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 85

Accepted Solution

by:
ozo earned 2000 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 85

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 35

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.

885 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