need help

suma

New Member
Joined
Nov 30, 2020
Messages
1
Reaction score
0
Credits
13
hi everyone i am new to Linux i am having trouble in understanding something so here is the problem when i create c file in home directory it is getting compiled, but when i move it to a sub folder inside home directory and try to compile it is showing no such file exist why so i want to know the reason please help me understand this
Screenshot from 2020-11-30 09-02-56.png
 


Hello.

i can't see any sub folder is selected in your screenshot. Can you give a terminal-screen with `ls -la` form this?
 
From your screen-shot - you appear to still be in your home directory. If you have moved the file function.c into another directory, then you either need to use the cd command to move into the directory containing your C file and then run your gcc command again - OR run gcc from your home directory and pass the full path to the C file.

e.g.
If you created a sub-directory called sub-dir and you moved the C file into sub-dir using a command like mv function.c ./sub-dir.

Then in order to compile function.c - you can do this:
Bash:
cd sub-dir
gcc function.c
In the above - the cd command moves us into the directory called sub-dir, then we invoke gcc which will compile your file and because you haven't specified a name for the output file, gcc will produce a file called a.out in sub-dir - or it might produce some error messages if you have any syntactical problems with your C file!

OR the other option - From inside your home directory, you could do this:
Bash:
gcc sub-dir/function.c

That tells gcc to compile the file function.c which is in sub-dir and will produce an executable file called a.out in your home directory.

Also, if you use gcc's -o option - you can specify the path/file-name for the output file produced by gcc.
e.g.
Bash:
gcc function.c -ofunction
Above tells gcc to create an executable in the current working directory called function.

There are a plethora of other options that can be used with gcc.
 
Last edited:

Staff online

Members online


Top