Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: gcc can't find file

  1. #1
    Join Date
    Dec 2011
    Beans
    12

    gcc can't find file

    I am new to Ubuntu Linux gcc. I have writen c++ programs for windows. I can't get off the ground with gcc. If I use gedit, do I store the hello.c in document? If so, why does:
    gcc first.c -o first
    not work. It can't find the file.

  2. #2
    Join Date
    Oct 2005
    Beans
    148

    Re: gcc can't find file

    1. Is it C++ or C file; for C files you use gcc command, for C++ g++
    2. Please post exactly the command you are using
    3. Show us the output of ls -la in the directory where you are compiling; hopefully it is not too crowded.
    4. Also tell us what is the error message
    Last edited by ubix; December 23rd, 2011 at 01:49 AM.

  3. #3
    Join Date
    May 2011
    Beans
    273

    Re: gcc can't find file

    Quote Originally Posted by DanWebb314 View Post
    I am new to Ubuntu Linux gcc. I have writen c++ programs for windows. I can't get off the ground with gcc. If I use gedit, do I store the hello.c in document? If so, why does:
    gcc first.c -o first
    not work. It can't find the file.
    You must run the command when you're in the same directory as the file. You probably used some IDE on Windows that took care of that.
    Your left hand is touching your face.

  4. #4
    Join Date
    Jun 2007
    Location
    Paraparaumu, New Zealand
    Beans
    Hidden!

    Re: gcc can't find file

    Thread moved to Programming Talk.

    Suppose you have the following c program saved in file hello.c:
    Code:
    #include <stdio.h>
    int main(void)
         {
         printf("Hello world!\n");
         return 0;
         }
    Assuming you've just saved the file, you would use something like this to compile it:
    Code:
    gcc hello.c -o hello
    Assuming it compiles correctly, you'd then need to run it with something like this:
    Code:
    ./hello
    EDIT/Disclaimer: the code shown is not intended as an example of good programming technique; it is included for illustrative purposes only.
    Last edited by lisati; December 23rd, 2011 at 02:01 AM.
    Forum DOs and DON'Ts
    Please use CODE tags
    Including your email address in a post is not recommended
    My Blog

  5. #5
    Join Date
    Jan 2007
    Location
    Location: Location:
    Beans
    1,246
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: gcc can't find file

    you need to issue the command from the directory in which you saved your source file. Or specify the absolute path to the source.


    Edit: D'oh, someone covered that above
    clear && echo paste url and press enter; read paste; (youtube-dl $paste) | zenity --progress --title="" --text "Downloading, please wait" --auto-close --pulsate && ans=$(zenity --file-selection); gnome-terminal -x mplayer "$ans"

  6. #6
    Join Date
    Oct 2005
    Beans
    148

    Re: gcc can't find file

    Enter the following in terminal:

    Code:
    mkdir my-c-test
    cd my-c-test
    echo "int main(void){}" > test1.c
    gcc test1.c -o test1
    ls -l

    You should now see something like:

    Code:
    -rwxr-xr-x 1 you you 8335 2011-12-22 20:10 test1
    -rw-r--r-- 1 you you   17 2011-12-22 20:10 test1.c

  7. #7
    Join Date
    Feb 2009
    Beans
    1,469

    Re: gcc can't find file

    Quote Originally Posted by lisati View Post
    EDIT/Disclaimer: the code shown is not intended as an example of good programming technique; it is included for illustrative purposes only.
    That's for sure -- you used Whitesmiths!

  8. #8
    Join Date
    Dec 2011
    Beans
    12

    Re: gcc can't find file

    Thank you!
    cd Documents
    makes a difference. Now I have compiled several 'hello world' programs.

    This question is just about solved.

    Should this question start a new thread?

    if i change "hello world" to "hello world\n", It does not like the escape sequence?

  9. #9
    Join Date
    May 2011
    Beans
    273

    Re: gcc can't find file

    Quote Originally Posted by DanWebb314 View Post
    Thank you!
    cd Documents
    makes a difference. Now I have compiled several 'hello world' programs.

    This question is just about solved.

    Should this question start a new thread?

    if i change "hello world" to "hello world\n", It does not like the escape sequence?
    That would mean newline. If you want to actually write \n, you'll have to write \\n.
    Your left hand is touching your face.

  10. #10
    Join Date
    Dec 2011
    Beans
    12

    Re: gcc can't find file

    Quote Originally Posted by Petrolea View Post
    That would mean newline. If you want to actually write \n, you'll have to write \\n.
    Yes I want new line. Why does the escape sequence '\n' not work?
    Last edited by DanWebb314; December 24th, 2011 at 09:06 PM. Reason: correct important spelling now to not! work

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •