the process of compiling c/c++ programs in linux
hey guys, I am a newbie to both Linux and the forum. this = first of hopefully many!
so i am a bit of a programmer, and i am used to the ease of ide's in windows, like bloodshed, in which you just hit compile to compile a program. i totally do not understand the process in linux, though. everyone says i should use g++, but i dont even think it is installed. (and the way to find out is to use the terminal, which is just a bunch of jargon to me at this point.) when i type in 'g++' in the terminal, it says: The program 'g++' can be found in the following packages: *g++ *pentium-builder Try: sudo apt-get install <select-package> bash: g++: command not found does that mean it is installed? i have no idea... so if i want to make a hello world program, i just write out something like this in text edit: #include <iostream> using namespace std; int main() {cout << "hello world"; return 0;} then name it hello.c, then type into terminal g++ hello.c ? what the hell is a make file? if you know of a good tutorial explaining this, that would be GREAT! thanks! |
oh yeah, i am running the latest version of ubuntu, whatever that is.
thanks! |
I'm guessing your using ubuntu?
to install g++ do Quote:
Quote:
report back so i can see how it went |
Quote:
You need to install g++, yep. Quote:
Quote:
They are like projects, but in my humble opinion, more versatile. If you are done to IDEs, there're many, but I suggest you to learn at least the basics of gcc and g++ before using anything else. There are thousands of tutorials on how to write a makefile, I don't think you will have problems finding that. |
okay, so it seems that g++ is up and working.
so then, i tried compiling this program: #include <iostream> using namespace std; int main() {cout << "hello world!"; return0;} under the name hello.c i put in to the command line g++ -o hello hello.c and lo and behold, upon the desktop a file called 'hello' appeared, with no extension or anything. i tried clicking on it, nothing. i tried putting in to the command line hello nothing. whats up? thanks for all the help! oh, i just got it. you have to type in ./hello is that the same for all programs? and is this called an 'executable?' thanks! |
Quote:
For example, if your program lives in /home/jochinome/ you could do this to run it: Code:
/home/jochinome/hello Code:
./hello Alternatively you could also put this file in /usr/local/bin or another location that is on your path. To see your current path you could use this: Code:
echo $PATH Code:
export PATH="$PATH:$HOME/bin" Feel free to ask for clarification if you need so. Quote:
There are lots of different executable files in linux, some are binary object code like those produced by C and compilers in general, just like the .exe files. Some others are scripts of any kind (perl, shell scripts which can also be of many types, lisp, ...). Postscript: I really don't want to sound like a purist smartass of anykind, but you really should correct the habit of using .c for c++ sources, in the future you are going to have problems if you stick to that in both IDEs and with gcc/g++. The compiler will assume that you are using c syntax if you use .c as the file extension, and that will confuse it. You can read all the extensions that the compiler accepts in the man page, look this string into the man page, and it will show you: Quote:
|
All times are GMT -5. The time now is 11:02 PM. |