r/C_Programming • • Sep 29 '26

Could not Compile

I used gcc to compile and run c file.

C prog file can be compile and run with no error, if the files are inside the same drive as gcc that is c: drive.

Program file inside the d: drive are not compile.

I just curious whether i made mistake or i need something to do.

0 Upvotes

14 comments sorted by

2

u/Imaginary_Dirt_5359 Sep 29 '26

Put your code here.

1

u/dkopgerpgdolfg Sep 29 '26

And what exact command was used

1

u/Vivid_Employment_950 Sep 29 '26

gcc .\hello.c -o .\hello

2

u/SmokeMuch7356 Sep 29 '26

What error message do you get from the compiler?

1

u/This_Growth2898 Sep 29 '26

This is a UNIX command. UNIX doesn't have C: or D: drives.

-3

u/Vivid_Employment_950 Sep 29 '26

even a simple code line to print hello, dosnt work.

There is no issue with c: drive

7

u/Snezzy_9245 Sep 29 '26

I was driving my car and it did something and now it doesn't. What is wrong? /s

1

u/Vivid_Employment_950 Sep 29 '26

UPDATE :
The c prog file is never compile, if the c program file is not in the same folder as gcc

3

u/syntactic_stevia Sep 29 '26

Shot in the dark, but did you forget to add the GCC bin folder to the PATH environmental variable?

1

u/dkopgerpgdolfg Sep 29 '26

gcc .\hello.c -o .\hello

The c prog file is never compile, if the c program file is not in the same folder as gcc

Well obviously. You're lacking total basics of CLI usage.

The dot means "the current directory". If you want something else, you need to specify a path, eg. D:\something\hello.c

There are also relative pathes, ".." for parent directories, etc.

1

u/SwordsAndElectrons Sep 29 '26

What folder do you execute the command from?

You need to learn the basics of how command line usage works.

gcc .\hello.c -o .\hello 

gcc will only be a valid command if you are currently in the folder with gcc or if that folder has been added to your PATH environment variable.

.\ means the current folder. That path will only resolve correctly if you are execute the command in that folder.

If the error you see says gcc is not a recognized command then I will guess that you are in the folder with your code and gcc is not included in PATH.

If the error you see indicates the source file isn't found then you either need to use full paths or navigate to the folder with your code first.

If you see something else then you should tell us what exactly you see and not a vague description of what isn't working.

3

u/Traveling-Techie Sep 29 '26

What’s the error message?

2

u/This_Growth2898 Sep 29 '26

What shell are you using? Provide all the commands you are using to compile your code in the first and the second situation (and the command to switch between)

1

u/CodingFishes Sep 29 '26

If you reference any libraries (include stdio.h), make sure they're available locally to the .c file you're trying to compile.