View Full Version : C compiler problems
December 3rd, 2008, 07:57 AM
I'm trying to compile my c code but when I type:
gcc: file.c: No such file or directory
gcc: no input files
Thanks for the help.
December 3rd, 2008, 08:34 AM
Where did you save your file?
December 3rd, 2008, 06:36 PM
Saved the file under my documents.
December 3rd, 2008, 06:37 PM
You need to be in your documents folder when you type this command.
December 3rd, 2008, 06:38 PM
Make sure you have build-essential installed by running
sudo apt-get install build-essential
Then make sure you're in the correct directory and run
gcc file.c -o file
That specifies what you want the output file to be called :)
December 3rd, 2008, 06:49 PM
How do I make sure I'm in the correct directory? I think that is my problem.
December 3rd, 2008, 06:52 PM
The command pwd will show you your current working directory.
December 3rd, 2008, 07:56 PM
And cd /your/path lets you navigate to other directories.
December 3rd, 2008, 11:27 PM
When operating the command line, you are always "in" a directory. Commands are executed relative to this directory.
Since the default directory to start in when opening a terminal is your home directory and you saved the source to the Documents folder, GCC cannot find your file.
The 'pwd' command is an abbreviation for Print Working Directory. Most of the time you don't need it though, since it should also be part of your prompt.
The 'cd' command means Change Directory. Since the Documents folder is located directly in your home folder, a simple 'cd Documents' should be enough for GCC to be able to find your file.
A useful feature of Bash (that sometimes works elsewhere) is that you can use '~' as short for your home directory. Meaning 'cd ~/Documents' is the same as 'cd /home/<username>/Documents'.
Running 'cd' without arguments returns you to your home directory.
For the purpose of illustration, you could also do:
gcc -o Documents/file Documents/file.c
By specifying a relative path.
December 4th, 2008, 12:34 AM
If you are using gnome and gnome-terminal, you may also use drag and drop to aid you. Just type in a terminal "gcc " (gcc followed by a space, but do not hit enter yet). Then locate your file.c with nautilus (the default "explorer"), and drag file.c to the terminal window. It should then fill in the correct path to the file for you. Hit enter to have it compile.
Another way to find your file is to search for it with the find command.
find ~ -name file.c If the file is somewhere under your homedir, that find command should find it.
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.