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!
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!
OS, compiler?
Sounds like using linux and gcc.
An Introduction to GCC - Table of Contents
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.
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.
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
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++
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
It's just telling you you don't have the source file (bkwrds_str.c) in your current directory
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