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












0















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)










share|improve this question

























  • 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 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








  • 1





    Your ls output appears to show a file called test - but no file called test.c

    – steeldriver
    Feb 21 at 0:24
















0















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)










share|improve this question

























  • 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 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








  • 1





    Your ls output appears to show a file called test - but no file called test.c

    – steeldriver
    Feb 21 at 0:24














0












0








0








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)










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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 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








  • 1





    Your ls output appears to show a file called test - but no file called test.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













  • 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













  • 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





    Your ls output appears to show a file called test - but no file called test.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










1 Answer
1






active

oldest

votes


















1















  1. Case is important, test.c is not test.C.

  2. gcc will actually accept either case .c, if it exists.

  3. gcc by default rejects extensionless files, but steeldriver showed you how to override that (which is certainly not standard practice).

  4. 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.

  5. 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.






share|improve this answer


























  • 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












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
});


}
});














draft saved

draft discarded


















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









1















  1. Case is important, test.c is not test.C.

  2. gcc will actually accept either case .c, if it exists.

  3. gcc by default rejects extensionless files, but steeldriver showed you how to override that (which is certainly not standard practice).

  4. 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.

  5. 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.






share|improve this answer


























  • 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
















1















  1. Case is important, test.c is not test.C.

  2. gcc will actually accept either case .c, if it exists.

  3. gcc by default rejects extensionless files, but steeldriver showed you how to override that (which is certainly not standard practice).

  4. 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.

  5. 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.






share|improve this answer


























  • 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














1












1








1








  1. Case is important, test.c is not test.C.

  2. gcc will actually accept either case .c, if it exists.

  3. gcc by default rejects extensionless files, but steeldriver showed you how to override that (which is certainly not standard practice).

  4. 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.

  5. 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.






share|improve this answer
















  1. Case is important, test.c is not test.C.

  2. gcc will actually accept either case .c, if it exists.

  3. gcc by default rejects extensionless files, but steeldriver showed you how to override that (which is certainly not standard practice).

  4. 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.

  5. 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.







share|improve this answer














share|improve this answer



share|improve this answer








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



















  • 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


















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

is 'sed' thread safe

How to make a Squid Proxy server?