By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,347 Members | 2,091 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,347 IT Pros & Developers. It's quick & easy.

C compilation error on RHEL3

P: n/a
Hi,

Myfile.c include a "Otherfile.h" and this file is under different
directory. When I compile Myfile.c, the compiler says "Otherfile.h: No
such file or directory" I include the path to "Otherfile.h" in PATH
environment variable. It still does not compile. Is there anything else
that I should do in this case? BTW, this linux (Red Hat linux) Thanks.

Apr 19 '06 #1
Share this Question
Share on Google+
21 Replies


P: n/a
thua...@hotmail.com wrote:
Hi,

Myfile.c include a "Otherfile.h" and this file is under different
directory. When I compile Myfile.c, the compiler says "Otherfile.h: No
such file or directory" I include the path to "Otherfile.h" in PATH
environment variable. It still does not compile. Is there anything else
that I should do in this case? BTW, this linux (Red Hat linux) Thanks.


The name of the include file is seached in an implementation defined
way, check your documentation for the details. Many implementations
allow you to specify the full pathname of the file or add directories
to be seached using a command-line option. For example, if you are
using gcc, check out the -I option.

Robert Gamble

Apr 19 '06 #2

P: n/a
th*****@hotmail.com wrote:

Myfile.c include a "Otherfile.h" and this file is under
different
directory. When I compile Myfile.c, the compiler says
"Otherfile.h: No
such file or directory" I include the path to "Otherfile.h" in
PATH
environment variable. It still does not compile. Is there
anything else
that I should do in this case?


Changing PATH will not do. Try:

#include "path/Otherfile.h"

Apr 19 '06 #3

P: n/a
th*****@hotmail.com wrote:
Myfile.c include a "Otherfile.h" and this file is under different
directory. When I compile Myfile.c, the compiler says "Otherfile.h: No
such file or directory" I include the path to "Otherfile.h" in PATH
environment variable. It still does not compile. Is there anything else
that I should do in this case? BTW, this linux (Red Hat linux) Thanks.

1. This query is not specific to ANSI C, and this group is quite strict
about off-topic posts. Check your system documentation.

2. If you checked your documentation you will find references to
something called the "include path". This is the key to your problem.
Apr 19 '06 #4

P: n/a
Vladimir S. Oka said:
th*****@hotmail.com wrote:

Myfile.c include a "Otherfile.h" and this file is under
different
directory. When I compile Myfile.c, the compiler says
"Otherfile.h: No
such file or directory" I include the path to "Otherfile.h" in
PATH
environment variable. It still does not compile. Is there
anything else
that I should do in this case?


Changing PATH will not do. Try:

#include "path/Otherfile.h"


Bad idea. Sorry, Vladimir, but that's a surefire way to make the code
non-portable.

Better: use the compiler's include path switch (e.g. in gcc it's -I) to
specify where to look for headers.

Better still: shove the headers in a place the compiler always looks in
anyway (e.g. /usr/local/include is common on Linux systems).
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Apr 19 '06 #5

P: n/a
th*****@hotmail.com wrote:
Hi,

Myfile.c include a "Otherfile.h" and this file is under different
directory. When I compile Myfile.c, the compiler says "Otherfile.h: No
such file or directory" I include the path to "Otherfile.h" in PATH
environment variable. It still does not compile. Is there anything
else that I should do in this case? BTW, this linux (Red Hat linux)

Most compilers have a method to set additional include paths. Check
your documentation, find a newsgroup or forum for your compiler, or
search the web for those words.

Brian
Apr 19 '06 #6

P: n/a
On 2006-04-19, Richard Heathfield <in*****@invalid.invalid> wrote:
Vladimir S. Oka said:
th*****@hotmail.com wrote:

Myfile.c include a "Otherfile.h" and this file is under
different
directory. When I compile Myfile.c, the compiler says
"Otherfile.h: No
such file or directory" I include the path to "Otherfile.h" in
PATH
environment variable. It still does not compile. Is there
anything else
that I should do in this case?
Changing PATH will not do. Try:

#include "path/Otherfile.h"


Bad idea. Sorry, Vladimir, but that's a surefire way to make the code
non-portable.


Why is it non-portable? The / will always work (even if the development
system uses a different directory separator), and so long as you stick
to relative paths (relative to the include directories for the build). I
always thought this should be all right.
[...]
Better still: shove the headers in a place the compiler always looks in
anyway (e.g. /usr/local/include is common on Linux systems).


<OT>

This might not be the best way to organize the headers in every case
though. It's a UNIX convention to put all the headers from all packages
in one place, all the executables from all packages in another place,
and all the libs in another. But on other systems things are organized
differently, for example the headers, executables and libs may all go
beneath different subdirectories for each package. On Windows for
example you see dirs called things like "C:\Program Files\My Favorite
Program\Include\" which is where the headers for "My Favorite Program"
go.

Also, thuang2 may not have write access to /usr/local/include.

</OT>
Apr 19 '06 #7

P: n/a
Ben C <sp******@spam.eggs> writes:
On 2006-04-19, Richard Heathfield <in*****@invalid.invalid> wrote:
Vladimir S. Oka said:
th*****@hotmail.com wrote:

Myfile.c include a "Otherfile.h" and this file is under
different
directory. When I compile Myfile.c, the compiler says
"Otherfile.h: No
such file or directory" I include the path to "Otherfile.h" in
PATH
environment variable. It still does not compile. Is there
anything else
that I should do in this case?

Changing PATH will not do. Try:

#include "path/Otherfile.h"


Bad idea. Sorry, Vladimir, but that's a surefire way to make the code
non-portable.


Why is it non-portable? The / will always work (even if the development
system uses a different directory separator), and so long as you stick
to relative paths (relative to the include directories for the build). I
always thought this should be all right.


What makes you think the / will always work? The standard makes no
such guarantee.

It happens to be interpreted as a directory delimiter on most modern
systems used for development (Unix-like systems, MS DOS and Windows),
and if you don't care about portability beyond such systems you can
use it. Things like "#include <sys/foobar.h>" are common on Unix-like
systems.

Otherwise, your best bet is to use just the name of the header file
and use some compiler-specific method to tell the compiler where to
look.
[...]
Better still: shove the headers in a place the compiler always looks in
anyway (e.g. /usr/local/include is common on Linux systems).


<OT>

This might not be the best way to organize the headers in every case
though. It's a UNIX convention to put all the headers from all packages
in one place, all the executables from all packages in another place,
and all the libs in another. But on other systems things are organized
differently, for example the headers, executables and libs may all go
beneath different subdirectories for each package. On Windows for
example you see dirs called things like "C:\Program Files\My Favorite
Program\Include\" which is where the headers for "My Favorite Program"
go.

Also, thuang2 may not have write access to /usr/local/include.

</OT>


Putting the headers for one particular project in a system-wide
directory is ok if and only if you want to make those headers
available system-wide. If they're local to one project, you probably
want to keep them in the directory (or directory tree) for that
project.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Apr 20 '06 #8

P: n/a
Richard Heathfield opined:
Vladimir S. Oka said:
#include "path/Otherfile.h"


Bad idea. Sorry, Vladimir, but that's a surefire way to make the code
non-portable.


You are, of course, absolutely right.

<OT type="excuse">
I should have refrained from testing Usenet access from my PDA on c.l.c
(in the header of the offending post you'll find: "User-Agent:
Yanoff-/3.2 (Palm)"). I actually thought I cancelled the post, but pen
based input on a tiny screen got the better of me.
</OT>

Anyway, I won't do it again...

--
Peace was the way.
-- Kirk, "The City on the Edge of Forever", stardate unknown

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>

Apr 20 '06 #9

P: n/a
On 2006-04-19, Keith Thompson <ks***@mib.org> wrote:
Ben C <sp******@spam.eggs> writes:
On 2006-04-19, Richard Heathfield <in*****@invalid.invalid> wrote:
Vladimir S. Oka said:
[snip]
#include "path/Otherfile.h" Bad idea. Sorry, Vladimir, but that's a surefire way to make the code
non-portable.
Why is it non-portable? The / will always work (even if the development
system uses a different directory separator), and so long as you stick
to relative paths (relative to the include directories for the build). I
always thought this should be all right.
What makes you think the / will always work? The standard makes no
such guarantee.
I drew the wrong conclusion from the fact that it usually does work.
It happens to be interpreted as a directory delimiter on most modern
systems used for development (Unix-like systems, MS DOS and Windows),


MS DOS (and some versions of Windows?) use \ in the shell, but you can
often use either \ or / in your #include directives.

As you say, though, this isn't standard, it's just the particular
preprocessor doing you a favour.

Thanks for putting me right on this one.
Apr 20 '06 #10

P: n/a

Ben C schrieb:

MS DOS (and some versions of Windows?) use \ in the shell, but you can
often use either \ or / in your #include directives.
Indeed, "/" should always be fine on DOS and successors, while "\\"
will never work on UN*X.
As you say, though, this isn't standard, it's just the particular
preprocessor doing you a favour.


Do you think the preprocessor interprets the character string between
".." or <...> in any way other than to pass it straight to fopen()?

Apr 20 '06 #11

P: n/a
On Wed, 19 Apr 2006 22:22:57 +0000, in comp.lang.c , Richard
Heathfield <in*****@invalid.invalid> wrote:
Bad idea. Sorry, Vladimir, but that's a surefire way to make the code
non-portable.
to a small extent. The "path/to/there/.h" syntax works on pretty much
all Osen I've worked with, including, surprisingly, VMS.
Better: use the compiler's include path switch (e.g. in gcc it's -I) to
specify where to look for headers.
Absolutely. Thats what the switch is for. :-)
Better still: shove the headers in a place the compiler always looks in
anyway (e.g. /usr/local/include is common on Linux systems).


Absolutely NOT. Do not clutter your local include dir with app
headers. :-(
Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Apr 20 '06 #12

P: n/a
Mark McIntyre said:
On Wed, 19 Apr 2006 22:22:57 +0000, in comp.lang.c , Richard
Heathfield <in*****@invalid.invalid> wrote:
Better still: shove the headers in a place the compiler always looks in
anyway (e.g. /usr/local/include is common on Linux systems).


Absolutely NOT. Do not clutter your local include dir with app
headers. :-(


I use it for library headers. App headers are what the cwd is for.

You might deduce from this that I don't split app source up into separate
directories. If it makes sense to split off a bunch of code into a separate
directory, chances are good that it's a useful bunch of code that will be
happier in a library.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Apr 20 '06 #13

P: n/a
On 2006-04-20, Ingo Menger <qu*********@consultant.com> wrote:

Ben C schrieb:

MS DOS (and some versions of Windows?) use \ in the shell, but you can
often use either \ or / in your #include directives.


Indeed, "/" should always be fine on DOS and successors, while "\\"
will never work on UN*X.


Yes, which is why it's usually better to use the '/', and also to
use the upper and lower case that the filenames actually have, because
this works on more platforms.
As you say, though, this isn't standard, it's just the particular
preprocessor doing you a favour.


Do you think the preprocessor interprets the character string between
".." or <...> in any way other than to pass it straight to fopen()?


I wondered about this, and then whether there's anything in any standard
about directory separators in paths passed into fopen, but couldn't find
anything.

Presumably then fopen with '/' as a directory separator works on MS DOS
etc.? The C standard doesn't of course require that #include be
implemented with fopen.
Apr 20 '06 #14

P: n/a
th*****@hotmail.com wrote:
Myfile.c include a "Otherfile.h" and this file is under different
directory. When I compile Myfile.c, the compiler says "Otherfile.h: No
such file or directory" I include the path to "Otherfile.h" in PATH
environment variable. It still does not compile...


<off-topic>
The PATH environment variable sets the directory list that the shell
will search for executable files. It has no connection whatsoever with
the search list used by the C compiler/preprocessor for included
files.
For gcc you must specify it with a -Ipath_to_included_file in the
command line.
</off-topic>

This is a platform specific question, as opposed to a C language
question. Next time please use a RedHat, gcc or Linux forum.
Apr 20 '06 #15

P: n/a
Roberto Waltman wrote:

th*****@hotmail.com wrote:
Myfile.c include a "Otherfile.h" and this file is under different
directory. When I compile Myfile.c, the compiler says "Otherfile.h: No
such file or directory" I include the path to "Otherfile.h" in PATH
environment variable. It still does not compile...
<off-topic>
The PATH environment variable sets the directory list that the shell
will search for executable files. It has no connection whatsoever with
the search list used by the C compiler/preprocessor for included
files.
For gcc you must specify it with a -Ipath_to_included_file in the
command line.


Some compilers use an environment variable similar to PATH, which is
used to list the #include directories, and is useful in that you don't
have to change scripts/makefiles/whatever you use to compile multiple
sets of files.

Again, however, this is dependent on your particular compiler.
</off-topic>


--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Apr 20 '06 #16

P: n/a
On Thu, 20 Apr 2006 14:21:49 +0000, in comp.lang.c , Richard
Heathfield <in*****@invalid.invalid> wrote:
Mark McIntyre said:
On Wed, 19 Apr 2006 22:22:57 +0000, in comp.lang.c , Richard
Heathfield <in*****@invalid.invalid> wrote:
Better still: shove the headers in a place the compiler always looks in
anyway (e.g. /usr/local/include is common on Linux systems).


Absolutely NOT. Do not clutter your local include dir with app
headers. :-(


I use it for library headers. App headers are what the cwd is for.

You might deduce from this that I don't split app source up into separate
directories. If it makes sense to split off a bunch of code into a separate
directory, chances are good that it's a useful bunch of code that will be
happier in a library.


I tend to distinguish quite carefully between a library thats private
to the current app, and a library thats shared amongst several apps.
Mark McIntyre
--
"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Apr 20 '06 #17

P: n/a
Mark McIntyre said:
I tend to distinguish quite carefully between a library thats private
to the current app, and a library thats shared amongst several apps.


If it's only ever going to be used by the current app, I generally won't
bother librarising it at all. I just pile it all into the app directory. If
that results in an unmanageable amount of source in that directory, it
almost certainly means I've missed an opportunity to factor out some
functionality that could be useful in other programs too.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Apr 20 '06 #18

P: n/a

Ben C schrieb:
On 2006-04-20, Ingo Menger <qu*********@consultant.com> wrote:
As you say, though, this isn't standard, it's just the particular
preprocessor doing you a favour.


Do you think the preprocessor interprets the character string between
".." or <...> in any way other than to pass it straight to fopen()?


I wondered about this, and then whether there's anything in any standard
about directory separators in paths passed into fopen, but couldn't find
anything.

Presumably then fopen with '/' as a directory separator works on MS DOS
etc.?


Yes it does. Some MS-DOS commands interpret the "/" in the commandline
as indicator for options, though. But this is a different story.
The C standard doesn't of course require that #include be
implemented with fopen.


Sure, but generally it does not make sense to parse a path name in an
application. It makes more sense to let the OS figure that out. The
reason why nothing is mentioned about directory separators (or, for
that matter, also drive letters) is most likely that the preprocessor
does not need to know anything about file systems, disk drives, mount
points, etc. It just needs a method to map a string (file name) to a
stream of bytes (file content).

Apr 20 '06 #19

P: n/a
Ben C <sp******@spam.eggs> writes:
On 2006-04-20, Ingo Menger <qu*********@consultant.com> wrote:

[...]
Do you think the preprocessor interprets the character string between
".." or <...> in any way other than to pass it straight to fopen()?


I wondered about this, and then whether there's anything in any standard
about directory separators in paths passed into fopen, but couldn't find
anything.


The standard says nothing about directories. As far as the C standard
is concerned, the file name passed to fopen() is just a string, to be
interpreted in some system-specific manner.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Apr 20 '06 #20

P: n/a
cthua...@hotmail.com wrote:
Myfile.c include a "Otherfile.h" and this file is under different
directory. When I compile Myfile.c, the compiler says "Otherfile.h: No
such file or directory" I include the path to "Otherfile.h" in PATH
environment variable. It still does not compile. Is there anything else
that I should do in this case? BTW, this linux (Red Hat linux) Thanks.
2. If you checked your documentation you will find references to
something called the "include path". This is the key to your problem.


How can I add more "include path" to gcc compiler on RHEL3. Thanks a
lot!

Apr 21 '06 #21

P: n/a
th*****@hotmail.com writes:
cthua...@hotmail.com wrote:
Myfile.c include a "Otherfile.h" and this file is under different
directory. When I compile Myfile.c, the compiler says "Otherfile.h: No
such file or directory" I include the path to "Otherfile.h" in PATH
environment variable. It still does not compile. Is there anything else
that I should do in this case? BTW, this linux (Red Hat linux) Thanks.

2. If you checked your documentation you will find references to
something called the "include path". This is the key to your problem.


How can I add more "include path" to gcc compiler on RHEL3. Thanks a
lot!


Asked and answered in another thread.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Apr 21 '06 #22

This discussion thread is closed

Replies have been disabled for this discussion.