Thread: compile prog from terminal

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    63

    compile prog from terminal

    I have googled compiling and running a program from the terminal but i am having trouble. Any help would be greatly appreciated! Thanks in advanced!

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    OS, compiler?
    Sounds like using linux and gcc.
    An Introduction to GCC - Table of Contents

  3. #3
    Registered User
    Join Date
    Sep 2010
    Posts
    63
    i was using code::blocks, an ide. I would like to try something new, more challenging! so i am trying to compile and run a c program from my Linux terminal. And yes, I think it is gcc.

  4. #4
    Registered User
    Join Date
    Sep 2010
    Posts
    63
    I tried to check out your link but it produces an error and says the server is busy each time i try and visit the site.

  5. #5
    Registered User
    Join Date
    Oct 2010
    Posts
    11
    That server is responding now, apparently.

    To simply compile, run:
    $ gcc -Wall -o hello_world hello_world.c
    ("$" is the shell prompt; don't type it.) "-Wall" tells GCC to output all warnings, and "-o" tells GCC where to write the output file. Now this is actually a two-step process--compiling the code into object format and then linking the objects into a binary executable file. To see this for yourself, you can run the following two commands:
    $ gcc -c -Wall -o hello_world.o hello_world.c
    $ gcc -Wall -o hello_world hello_world.c
    The first compiles ("-c" tells GCC to compile only), and the second links. This is useful in large builds, where you may want to perform each step separately to isolate errors and is usually done in Makefiles or shell scripts to automate the process.

    GCC should automatically set the mode of the file so that you can execute it, so execution is as simple as:
    $ ./hello_world

  6. #6
    Registered User
    Join Date
    Sep 2010
    Posts
    63
    Ok PehJota now the concept that i am not understanding is "hello_world hello_world.c" i work with the terminal a lot so i shouldn't have much trouble! But the first is where i want to save the file? So if i had a path named ~/Documents/C/C++/ (Name the file) hello_world.c so it would look like: gcc -Wall -o ~/Documents/C/C++/ hello_world.c

  7. #7
    Registered User
    Join Date
    Jan 2010
    Location
    Ca, US
    Posts
    29
    Quote Originally Posted by codecaine_21 View Post
    Ok PehJota now the concept that i am not understanding is "hello_world hello_world.c" i work with the terminal a lot so i shouldn't have much trouble! But the first is where i want to save the file? So if i had a path named ~/Documents/C/C++/ (Name the file) hello_world.c so it would look like: gcc -Wall -o ~/Documents/C/C++/ hello_world.c
    "hello_world.c" is just the name of the source file you want to compile.
    If you use the -o option you must tell gcc what name you want to give your compiled program not just the location.

    gcc -Wall -o hello_world hello_world.c

    That assumes you're in ~/Documents/C/C++

  8. #8
    Registered User
    Join Date
    Sep 2010
    Posts
    63
    This is what i get when i run the commands

    Code:
    anthony@anthony:~$ gcc -Wall -o bkwrds_str bkwrds_str.c
    gcc: bkwrds_str.c: No such file or directory
    gcc: no input files

  9. #9
    Registered User
    Join Date
    Jan 2010
    Location
    Ca, US
    Posts
    29
    It's just telling you you don't have the source file (bkwrds_str.c) in your current directory

  10. #10
    Registered User
    Join Date
    Sep 2010
    Posts
    63
    Ok now i see! I have to be in the current directory that the file is in. Sorry i am a little slow lol Thank y'all

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to compile mfc libs from platform sdk
    By tjcbs in forum Windows Programming
    Replies: 6
    Last Post: 11-19-2006, 08:20 AM
  2. Compile crashes certain windows
    By Loduwijk in forum C++ Programming
    Replies: 5
    Last Post: 03-26-2006, 09:05 PM
  3. open scene graph compile issues
    By ichijoji in forum Game Programming
    Replies: 1
    Last Post: 08-04-2005, 12:31 PM
  4. compile program?
    By Goosie in forum C++ Programming
    Replies: 9
    Last Post: 06-22-2005, 02:26 PM
  5. Quick Makefile Question
    By cisokay in forum C++ Programming
    Replies: 6
    Last Post: 05-16-2005, 06:28 PM