top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to include header file during compilation?

+2 votes
1,299 views

Is there any option available to include header file while compiling?

For Ex:
i don't want to write "#include<stdio.h>" in my .c file. but while compiling i want to include it.
(like, $: cc 1.c -option stdio.h)
can it be done?

posted May 21, 2015 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

You can use -i option on command line durning compilation.

answer May 23, 2015 by Amit Kumar Pandey
Thanks,
But "-i" is not working.
showing that,"Error : unrecognized command line option -i "
0 votes

Try something
gcc -o hello 1.c stdio.h

(you may need to provide the include path i.e. -I)

I have not tested but let me know if it works or not.

answer May 25, 2015 by Salil Agrawal
No..
"No such file or directory : stdio.h"
I think I have already explained in my answer, u need to give  the path -I (capital I followed by the path and no space between path and -I)
No Sir,
Still not working,
"gcc -o hello 1.c -I/usr/include/stdio.h"


Can you please write the format for including stdio.h?
Try
gcc -o hello 1.c  stdio.h -I/usr/include/
"No such file or directory : stdio.h"
Tested -
gcc -o hello 1.c  /usr/include/stdio.h

u may get some warning but hello would be created.
Sir, That warnings will be there even if we don't include header file at all.
I guess, by this way header file is not included.
Not sure this is the man page of gcc which does not seems to have any option (other then -I which is just path)
       gcc [-c|-S|-E] [-std=standard]
           [-g] [-pg] [-Olevel]
           [-Wwarn...] [-Wpedantic]
           [-Idir...] [-Ldir...]
           [-Dmacro[=defn]...] [-Umacro]
           [-foption...] [-mmachine-option...]
           [-o outfile] [@file] infile...

So seems the only and correct way to include is include method, by the way why you dont want to include the file using include method.
I have been asked this question in interview, and i couldn't answer it. so.
Anyways thanks for your time sir,
...