Where are the c header files on my system?
Kevin D. Clark
kevin_d_clark at comcast.net
Tue May 19 08:48:44 EDT 2009
Lori Nagel writes:
> I've been using gcc in Linux and cc in Unix. I have not been using
> an IDE, only the terminal shell and a text editing program for the C
> files. On both computers c programs compile and run, however, the
> compilers are different and have different options, and some code
> that compiles and runs on one doesn't on the other. (what I mean is
> why is gcc so lax while cc is so mean.)
I strongly recommend that when you compile all of your C code with gcc
that you add the arguments "-Werror -Wall -Wcast-qual".
You can either do this or spend your time chasing crazy problems.
Your choice.
> What I want to know is if there any easy way I could find out where
> my .h files are on my computers such as stdio.h? Also, would I be
> able to find the function prototypes for things like scanf in them
> or would I have to go somewhere else?
If you want to know where to #include things from, the very first
place you should look is in the manual page. If you type "man scanf"
you will see this:
SYNOPSIS
#include <stdio.h>
int scanf(const char *format, ...);
int fscanf(FILE *stream, const char *format, ...);
int sscanf(const char *str, const char *format, ...);
The way that you should interpret this is "if I want to use the
scanf() function, I need to #include <stdio.h> in my code.
> Another thing, why oh why did they decide to seperate out libm.a
> from the rest of the C programming libriaries so that you have to
> include it? It used to make me so upset until I read intro to gcc.
Again, the problem that you are describing here is easily remedied if
you consult the manual page. For example, "man atanf" produces:
SYNOPSIS
#include <math.h>
double atan(double x);
float atanf(float x);
long double atanl( long double x);
Link with -lm.
You should interpret this to mean (1) if you want to use the math
library, you need to #include <math.h> and (2) if you want to use the
math library, you need to link against it by adding the argument "-lm"
to your invocation of the linker, like so: "cc foo.o -o foo -lm".
> Please someone answer my question because I have been wanting to
> know the answer for about 3 years now, and I think that is a long
> enough time to wait. I have done enough reading of manuals to know
> that most of them don't answer the questions that people have. I'm
> planning to write the ultimate newbie C programming book for
> Gnu/Linux because it doesn't currently exist.
The two best books that I know of on the C language are Kernighan and
Ritchie's book and Harbison and Steele's book.
Regards,
--kevin
--
GnuPG ID: B280F24E God, I loved that Pontiac.
alumni.unh.edu!kdc -- Tom Waits
http://kdc-blog.blogspot.com/
More information about the gnhlug-discuss
mailing list