Solved

c language help - file paths

Posted on 2014-03-02
7
113 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 32

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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.

760 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

20 Experts available now in Live!

Get 1:1 Help Now