How to add source code directory to gcc's search path?

10,248

There's no option in GCC that does what you want. If you don't want to type out the entire name, simply cd C:\C and then run gcc prog.c -o ha. GCC's translation unit parameters are always either absolute or relative to the current working directory.

Share:
10,248
reb94
Author by

reb94

Updated on September 04, 2022

Comments

  • reb94
    reb94 over 1 year

    I searched here and found this : How to add path to gcc's search dirs?

    But it doesn't answer my question. I want to add a path to the programs section.

    I have stored the source code at C:\C\ but everytime I try to compile these programs by gcc prog.c -o ha, it says "No such file or directory". I have to type the entire path everytime. Also tell me how to remove a directory from gcc's programs path.

  • reb94
    reb94 about 11 years
    I use Windows. I tried this command but it doesn't work. I got the same error again. gcc -I/C:/C/ prog.c
  • reb94
    reb94 about 11 years
    Here's what I did. I added C:\C`to the path environment variables. I opened cmd and typed gcc prog.cbut it still shows the same error. Do I still have to type gcc C:\C\prog.c`?
  • reb94
    reb94 about 11 years
    I changed the directory and then typed gcc prog.c and it worked. After this, ho do I run the program? I tried typing prog and ./prog but none of them worked.
  • reb94
    reb94 about 11 years
    If I don't specify the name of output file myself, it automtically names it as "a.exe" and hence typing prog does not work. But why does this happen? Why is the output file not named as "prog.exe"?
  • Yam Marcovic
    Yam Marcovic almost 11 years
    Sorry for the late reply. But the answer is that gcc, by default, outputs the file "a.exe" or "a.out" (on UNIX). You need to tell it the name of the output file you want, if you want something different, e.h. "gcc -o prog.exe prog.c". The reason is that in real projects, you mostly specify more than one input file, for later linkage, and hence there's no point in trying to infer the name you want in those cases... So to keep it simple, it's that way for all cases.