Solved

c language help - file paths

Posted on 2014-03-02
7
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 34

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
The goal of this video is to provide viewers with basic examples to understand recursion 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.

726 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