gcc “no such file or directory” error when attempting compilation

Multi tool use
I just moved to Ubuntu and am currently learning C programming, so naturally I tried to compile some code. I am sure I'm using the command right (it's just a few letters, come on), but the compiler keeps complaining about there being "no such file or directory", regardless of what directory I try to compile from. I have build-essential installed and gcc seems to be functioning normally otherwise, what could be the cause of this? Help is much appreciated.
Edit: Upon further investigation, I've realised that this happens with .c files I create through an editor, such as the default Ubuntu editor or Atom. The result was succesfull when using the gedit command, but unsuccesfull when creating the same file through an editor. I also saved the files to the home directory and ran ls
every time to make sure that they're there before attempting to compile. Here's the error message:
me@My-PC:~$ gcc test.c
gcc: error: test.c: No such file or directory
gcc: fatal error: no input files
compilation terminated.
Edit2: I was being an idiot and not saving the files as .c (I assumed setting the format to "C" in the editors would do that for me)
compiling gcc
|
show 3 more comments
I just moved to Ubuntu and am currently learning C programming, so naturally I tried to compile some code. I am sure I'm using the command right (it's just a few letters, come on), but the compiler keeps complaining about there being "no such file or directory", regardless of what directory I try to compile from. I have build-essential installed and gcc seems to be functioning normally otherwise, what could be the cause of this? Help is much appreciated.
Edit: Upon further investigation, I've realised that this happens with .c files I create through an editor, such as the default Ubuntu editor or Atom. The result was succesfull when using the gedit command, but unsuccesfull when creating the same file through an editor. I also saved the files to the home directory and ran ls
every time to make sure that they're there before attempting to compile. Here's the error message:
me@My-PC:~$ gcc test.c
gcc: error: test.c: No such file or directory
gcc: fatal error: no input files
compilation terminated.
Edit2: I was being an idiot and not saving the files as .c (I assumed setting the format to "C" in the editors would do that for me)
compiling gcc
Welcome to Ask Ubuntu. We may be able to help more if you provide the command & error message exactly (ie. copy & paste it). My guess is you didn't provide the full name (eg. my-program.c where the full name is required including the .c ending) - but without your command & actual error we can only guess like I just did. Your release of Ubuntu isn't essential, but is still helpful as later releases run later versions ofgcc
which often have different defaults
– guiverc
Feb 21 at 0:08
I've posted the error message. As I have mentioned in the edit the error seems to be in some way tied to code I create through editors, somehow gedit was not affected
– V.Ch.
Feb 21 at 0:16
Most likely, the editor you are using to create the.c
files is saving them to a directory that's different from the one in which you are executing thegcc
command: check what files are in the current directory usingls
– steeldriver
Feb 21 at 0:16
I am sure that is not the case. While testing for this error I kept saving the.c
files to the home directory, which is the default directory for the terminal, thus ensuring I don't move somewhere by accident withcd
. I have done exactly as you've said, ranls
each time to make sure that the file is present before attempting to compile. The result is still the same
– V.Ch.
Feb 21 at 0:18
1
Yourls
output appears to show a file calledtest
- but no file calledtest.c
– steeldriver
Feb 21 at 0:24
|
show 3 more comments
I just moved to Ubuntu and am currently learning C programming, so naturally I tried to compile some code. I am sure I'm using the command right (it's just a few letters, come on), but the compiler keeps complaining about there being "no such file or directory", regardless of what directory I try to compile from. I have build-essential installed and gcc seems to be functioning normally otherwise, what could be the cause of this? Help is much appreciated.
Edit: Upon further investigation, I've realised that this happens with .c files I create through an editor, such as the default Ubuntu editor or Atom. The result was succesfull when using the gedit command, but unsuccesfull when creating the same file through an editor. I also saved the files to the home directory and ran ls
every time to make sure that they're there before attempting to compile. Here's the error message:
me@My-PC:~$ gcc test.c
gcc: error: test.c: No such file or directory
gcc: fatal error: no input files
compilation terminated.
Edit2: I was being an idiot and not saving the files as .c (I assumed setting the format to "C" in the editors would do that for me)
compiling gcc
I just moved to Ubuntu and am currently learning C programming, so naturally I tried to compile some code. I am sure I'm using the command right (it's just a few letters, come on), but the compiler keeps complaining about there being "no such file or directory", regardless of what directory I try to compile from. I have build-essential installed and gcc seems to be functioning normally otherwise, what could be the cause of this? Help is much appreciated.
Edit: Upon further investigation, I've realised that this happens with .c files I create through an editor, such as the default Ubuntu editor or Atom. The result was succesfull when using the gedit command, but unsuccesfull when creating the same file through an editor. I also saved the files to the home directory and ran ls
every time to make sure that they're there before attempting to compile. Here's the error message:
me@My-PC:~$ gcc test.c
gcc: error: test.c: No such file or directory
gcc: fatal error: no input files
compilation terminated.
Edit2: I was being an idiot and not saving the files as .c (I assumed setting the format to "C" in the editors would do that for me)
compiling gcc
compiling gcc
edited Feb 21 at 0:36
V.Ch.
asked Feb 21 at 0:03
V.Ch.V.Ch.
14
14
Welcome to Ask Ubuntu. We may be able to help more if you provide the command & error message exactly (ie. copy & paste it). My guess is you didn't provide the full name (eg. my-program.c where the full name is required including the .c ending) - but without your command & actual error we can only guess like I just did. Your release of Ubuntu isn't essential, but is still helpful as later releases run later versions ofgcc
which often have different defaults
– guiverc
Feb 21 at 0:08
I've posted the error message. As I have mentioned in the edit the error seems to be in some way tied to code I create through editors, somehow gedit was not affected
– V.Ch.
Feb 21 at 0:16
Most likely, the editor you are using to create the.c
files is saving them to a directory that's different from the one in which you are executing thegcc
command: check what files are in the current directory usingls
– steeldriver
Feb 21 at 0:16
I am sure that is not the case. While testing for this error I kept saving the.c
files to the home directory, which is the default directory for the terminal, thus ensuring I don't move somewhere by accident withcd
. I have done exactly as you've said, ranls
each time to make sure that the file is present before attempting to compile. The result is still the same
– V.Ch.
Feb 21 at 0:18
1
Yourls
output appears to show a file calledtest
- but no file calledtest.c
– steeldriver
Feb 21 at 0:24
|
show 3 more comments
Welcome to Ask Ubuntu. We may be able to help more if you provide the command & error message exactly (ie. copy & paste it). My guess is you didn't provide the full name (eg. my-program.c where the full name is required including the .c ending) - but without your command & actual error we can only guess like I just did. Your release of Ubuntu isn't essential, but is still helpful as later releases run later versions ofgcc
which often have different defaults
– guiverc
Feb 21 at 0:08
I've posted the error message. As I have mentioned in the edit the error seems to be in some way tied to code I create through editors, somehow gedit was not affected
– V.Ch.
Feb 21 at 0:16
Most likely, the editor you are using to create the.c
files is saving them to a directory that's different from the one in which you are executing thegcc
command: check what files are in the current directory usingls
– steeldriver
Feb 21 at 0:16
I am sure that is not the case. While testing for this error I kept saving the.c
files to the home directory, which is the default directory for the terminal, thus ensuring I don't move somewhere by accident withcd
. I have done exactly as you've said, ranls
each time to make sure that the file is present before attempting to compile. The result is still the same
– V.Ch.
Feb 21 at 0:18
1
Yourls
output appears to show a file calledtest
- but no file calledtest.c
– steeldriver
Feb 21 at 0:24
Welcome to Ask Ubuntu. We may be able to help more if you provide the command & error message exactly (ie. copy & paste it). My guess is you didn't provide the full name (eg. my-program.c where the full name is required including the .c ending) - but without your command & actual error we can only guess like I just did. Your release of Ubuntu isn't essential, but is still helpful as later releases run later versions of
gcc
which often have different defaults– guiverc
Feb 21 at 0:08
Welcome to Ask Ubuntu. We may be able to help more if you provide the command & error message exactly (ie. copy & paste it). My guess is you didn't provide the full name (eg. my-program.c where the full name is required including the .c ending) - but without your command & actual error we can only guess like I just did. Your release of Ubuntu isn't essential, but is still helpful as later releases run later versions of
gcc
which often have different defaults– guiverc
Feb 21 at 0:08
I've posted the error message. As I have mentioned in the edit the error seems to be in some way tied to code I create through editors, somehow gedit was not affected
– V.Ch.
Feb 21 at 0:16
I've posted the error message. As I have mentioned in the edit the error seems to be in some way tied to code I create through editors, somehow gedit was not affected
– V.Ch.
Feb 21 at 0:16
Most likely, the editor you are using to create the
.c
files is saving them to a directory that's different from the one in which you are executing the gcc
command: check what files are in the current directory using ls
– steeldriver
Feb 21 at 0:16
Most likely, the editor you are using to create the
.c
files is saving them to a directory that's different from the one in which you are executing the gcc
command: check what files are in the current directory using ls
– steeldriver
Feb 21 at 0:16
I am sure that is not the case. While testing for this error I kept saving the
.c
files to the home directory, which is the default directory for the terminal, thus ensuring I don't move somewhere by accident with cd
. I have done exactly as you've said, ran ls
each time to make sure that the file is present before attempting to compile. The result is still the same– V.Ch.
Feb 21 at 0:18
I am sure that is not the case. While testing for this error I kept saving the
.c
files to the home directory, which is the default directory for the terminal, thus ensuring I don't move somewhere by accident with cd
. I have done exactly as you've said, ran ls
each time to make sure that the file is present before attempting to compile. The result is still the same– V.Ch.
Feb 21 at 0:18
1
1
Your
ls
output appears to show a file called test
- but no file called test.c
– steeldriver
Feb 21 at 0:24
Your
ls
output appears to show a file called test
- but no file called test.c
– steeldriver
Feb 21 at 0:24
|
show 3 more comments
1 Answer
1
active
oldest
votes
- Case is important, test.c is not test.C.
- gcc will actually accept either case .c, if it exists.
- gcc by default rejects extensionless files, but steeldriver showed you how to override that (which is certainly not standard practice).
- gcc can produce an output for a name you supply, -o test.out using your example. The standard user setup includes a bin directory in the home directory, and this is the usual place to add private scripts because it is already in your PATH. For instance, in ~/bin, add a file named mygcc containing
gcc -o "$1".out ${1}.c
to compile your files anywhere with the new command mygcc test
Alter to fit your needs -- pass explicit names executables, pass the entire test.c name, etc. - Running from the local directory without the ./ (as ./test.out) is
made possible by adding "." to the PATH variable (edit the .profile
in your home directory to do this)
The .profile file in your home directory is just a text file owned my you, so any editor will work, but choose one which will not wrap lines for you. The PATH variable is usually set up near the bottom, so you may add the :. to the end of an existing PATH=... line, or make a new one like
PATH=${PATH}:.
Adding the . to the end is "safer" than at the beginning, so it cannot override any system programs of the same name. Running any non-system program entails some risk, (where did it come from, what does it do,...?) but if the program is one you are creating (source and all), those risks are less. It may be worth the convenience to test new compiled programs, your choice.
Thank you for your exhaustive answer. With regard to editing the PATH variable, a quick google search suggests that this is not the best thing to do, as security and naming issues may arise from this. Should i disregard these? Also, how exactly do i edit it?
– V.Ch.
Feb 21 at 12:15
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1119977%2fgcc-no-such-file-or-directory-error-when-attempting-compilation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
- Case is important, test.c is not test.C.
- gcc will actually accept either case .c, if it exists.
- gcc by default rejects extensionless files, but steeldriver showed you how to override that (which is certainly not standard practice).
- gcc can produce an output for a name you supply, -o test.out using your example. The standard user setup includes a bin directory in the home directory, and this is the usual place to add private scripts because it is already in your PATH. For instance, in ~/bin, add a file named mygcc containing
gcc -o "$1".out ${1}.c
to compile your files anywhere with the new command mygcc test
Alter to fit your needs -- pass explicit names executables, pass the entire test.c name, etc. - Running from the local directory without the ./ (as ./test.out) is
made possible by adding "." to the PATH variable (edit the .profile
in your home directory to do this)
The .profile file in your home directory is just a text file owned my you, so any editor will work, but choose one which will not wrap lines for you. The PATH variable is usually set up near the bottom, so you may add the :. to the end of an existing PATH=... line, or make a new one like
PATH=${PATH}:.
Adding the . to the end is "safer" than at the beginning, so it cannot override any system programs of the same name. Running any non-system program entails some risk, (where did it come from, what does it do,...?) but if the program is one you are creating (source and all), those risks are less. It may be worth the convenience to test new compiled programs, your choice.
Thank you for your exhaustive answer. With regard to editing the PATH variable, a quick google search suggests that this is not the best thing to do, as security and naming issues may arise from this. Should i disregard these? Also, how exactly do i edit it?
– V.Ch.
Feb 21 at 12:15
add a comment |
- Case is important, test.c is not test.C.
- gcc will actually accept either case .c, if it exists.
- gcc by default rejects extensionless files, but steeldriver showed you how to override that (which is certainly not standard practice).
- gcc can produce an output for a name you supply, -o test.out using your example. The standard user setup includes a bin directory in the home directory, and this is the usual place to add private scripts because it is already in your PATH. For instance, in ~/bin, add a file named mygcc containing
gcc -o "$1".out ${1}.c
to compile your files anywhere with the new command mygcc test
Alter to fit your needs -- pass explicit names executables, pass the entire test.c name, etc. - Running from the local directory without the ./ (as ./test.out) is
made possible by adding "." to the PATH variable (edit the .profile
in your home directory to do this)
The .profile file in your home directory is just a text file owned my you, so any editor will work, but choose one which will not wrap lines for you. The PATH variable is usually set up near the bottom, so you may add the :. to the end of an existing PATH=... line, or make a new one like
PATH=${PATH}:.
Adding the . to the end is "safer" than at the beginning, so it cannot override any system programs of the same name. Running any non-system program entails some risk, (where did it come from, what does it do,...?) but if the program is one you are creating (source and all), those risks are less. It may be worth the convenience to test new compiled programs, your choice.
Thank you for your exhaustive answer. With regard to editing the PATH variable, a quick google search suggests that this is not the best thing to do, as security and naming issues may arise from this. Should i disregard these? Also, how exactly do i edit it?
– V.Ch.
Feb 21 at 12:15
add a comment |
- Case is important, test.c is not test.C.
- gcc will actually accept either case .c, if it exists.
- gcc by default rejects extensionless files, but steeldriver showed you how to override that (which is certainly not standard practice).
- gcc can produce an output for a name you supply, -o test.out using your example. The standard user setup includes a bin directory in the home directory, and this is the usual place to add private scripts because it is already in your PATH. For instance, in ~/bin, add a file named mygcc containing
gcc -o "$1".out ${1}.c
to compile your files anywhere with the new command mygcc test
Alter to fit your needs -- pass explicit names executables, pass the entire test.c name, etc. - Running from the local directory without the ./ (as ./test.out) is
made possible by adding "." to the PATH variable (edit the .profile
in your home directory to do this)
The .profile file in your home directory is just a text file owned my you, so any editor will work, but choose one which will not wrap lines for you. The PATH variable is usually set up near the bottom, so you may add the :. to the end of an existing PATH=... line, or make a new one like
PATH=${PATH}:.
Adding the . to the end is "safer" than at the beginning, so it cannot override any system programs of the same name. Running any non-system program entails some risk, (where did it come from, what does it do,...?) but if the program is one you are creating (source and all), those risks are less. It may be worth the convenience to test new compiled programs, your choice.
- Case is important, test.c is not test.C.
- gcc will actually accept either case .c, if it exists.
- gcc by default rejects extensionless files, but steeldriver showed you how to override that (which is certainly not standard practice).
- gcc can produce an output for a name you supply, -o test.out using your example. The standard user setup includes a bin directory in the home directory, and this is the usual place to add private scripts because it is already in your PATH. For instance, in ~/bin, add a file named mygcc containing
gcc -o "$1".out ${1}.c
to compile your files anywhere with the new command mygcc test
Alter to fit your needs -- pass explicit names executables, pass the entire test.c name, etc. - Running from the local directory without the ./ (as ./test.out) is
made possible by adding "." to the PATH variable (edit the .profile
in your home directory to do this)
The .profile file in your home directory is just a text file owned my you, so any editor will work, but choose one which will not wrap lines for you. The PATH variable is usually set up near the bottom, so you may add the :. to the end of an existing PATH=... line, or make a new one like
PATH=${PATH}:.
Adding the . to the end is "safer" than at the beginning, so it cannot override any system programs of the same name. Running any non-system program entails some risk, (where did it come from, what does it do,...?) but if the program is one you are creating (source and all), those risks are less. It may be worth the convenience to test new compiled programs, your choice.
edited Feb 21 at 17:28
answered Feb 21 at 1:25
ubfan1ubfan1
9,89441730
9,89441730
Thank you for your exhaustive answer. With regard to editing the PATH variable, a quick google search suggests that this is not the best thing to do, as security and naming issues may arise from this. Should i disregard these? Also, how exactly do i edit it?
– V.Ch.
Feb 21 at 12:15
add a comment |
Thank you for your exhaustive answer. With regard to editing the PATH variable, a quick google search suggests that this is not the best thing to do, as security and naming issues may arise from this. Should i disregard these? Also, how exactly do i edit it?
– V.Ch.
Feb 21 at 12:15
Thank you for your exhaustive answer. With regard to editing the PATH variable, a quick google search suggests that this is not the best thing to do, as security and naming issues may arise from this. Should i disregard these? Also, how exactly do i edit it?
– V.Ch.
Feb 21 at 12:15
Thank you for your exhaustive answer. With regard to editing the PATH variable, a quick google search suggests that this is not the best thing to do, as security and naming issues may arise from this. Should i disregard these? Also, how exactly do i edit it?
– V.Ch.
Feb 21 at 12:15
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1119977%2fgcc-no-such-file-or-directory-error-when-attempting-compilation%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
ZuRKcKOTThZCCm1PE,nNv4n baMujJI8M9Zs2ZxceH GVis iy5Q5rI9YcH,0fh
Welcome to Ask Ubuntu. We may be able to help more if you provide the command & error message exactly (ie. copy & paste it). My guess is you didn't provide the full name (eg. my-program.c where the full name is required including the .c ending) - but without your command & actual error we can only guess like I just did. Your release of Ubuntu isn't essential, but is still helpful as later releases run later versions of
gcc
which often have different defaults– guiverc
Feb 21 at 0:08
I've posted the error message. As I have mentioned in the edit the error seems to be in some way tied to code I create through editors, somehow gedit was not affected
– V.Ch.
Feb 21 at 0:16
Most likely, the editor you are using to create the
.c
files is saving them to a directory that's different from the one in which you are executing thegcc
command: check what files are in the current directory usingls
– steeldriver
Feb 21 at 0:16
I am sure that is not the case. While testing for this error I kept saving the
.c
files to the home directory, which is the default directory for the terminal, thus ensuring I don't move somewhere by accident withcd
. I have done exactly as you've said, ranls
each time to make sure that the file is present before attempting to compile. The result is still the same– V.Ch.
Feb 21 at 0:18
1
Your
ls
output appears to show a file calledtest
- but no file calledtest.c
– steeldriver
Feb 21 at 0:24