LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   starting C++ programming (https://www.linuxquestions.org/questions/linux-newbie-8/starting-c-programming-4175424159/)

gerdy 08-27-2012 02:38 AM

starting C++ programming
 
I have been reading C++ tutorials and stuff online and want to start making my own programs and stuff. one of the first things I noticed is that I have to have a compiler. the page I read mentioned that most GNU os's come with a compiler. I can't find any kind of compiler right now. So where do I start for the compilers and what not for C++?

414N 08-27-2012 02:42 AM

You should at least tell which distro you're using for us to be of any help.
Assuming you're on Ubuntu, you need to install the build-essential package.
You can find some more info here.

knudfl 08-27-2012 02:42 AM

Ubuntu : sudo apt-get install g++

...

gerdy 08-27-2012 02:44 AM

I'm using Ubuntu 12.04. and after I do sudo apt-get G++, how do I run the programs I create?

pan64 08-27-2012 02:49 AM

when you create a program you will use an option like this: g++ -o <filename> <other options>. This filename is your result and is executable, so you can run it just by typing the name.
For example g++ -o helloworld helloworld.c will create a file named helloworld and you can execute it as: helloworld.

gerdy 08-27-2012 02:49 AM

thanks for the sudo apt-get install g++. what do I save my files as for g++?

---------- Post added 08-27-12 at 12:20 PM ----------

awesome. thank you! so .C is the extension?

pan64 08-27-2012 02:54 AM

see getting started on this page: http://www3.wooster.edu/cs/studentRes/gccTutorial.php

gerdy 08-27-2012 02:58 AM

so I made the famous helloworld.C file and saved it on my desktop, when I try to compile it, and do the g++ -o hello.C, it came up with

g++ -o /home/ethan/Desktop/hello.C
g++: fatal error: no input files
compilation terminated.

please note-top line is what I input.

gerdy 08-27-2012 03:01 AM

thanks for that link.

pan64 08-27-2012 03:02 AM

gerdy, you need to specify both the source and the resuld files, like:
g++ -o <result> <sources>
In your example you have not specified any source (or input) file, just an output file which was /home/ethan/Desktop/hello.C

414N 08-27-2012 03:16 AM

Also, please note that C++ source files should have .cpp suffix, not .c.


All times are GMT -5. The time now is 02:38 AM.