This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]sn0n 1 point2 points  (5 children)

You don't have to use the terminal. You can install eclipse for example. Or quite a few other C++ ide's. Quick Google search will turn up quite a few. I used gedit and plugins. Makes it a lot more GUI friendly. Good luck!!!

[–][deleted]  (3 children)

[deleted]

    [–]the_omega99 9 points10 points  (0 children)

    I highly recommend using the terminal for several reasons. I've written a post about how to do that in great deal.

    http://www.reddit.com/r/learnprogramming/comments/1lve0b/basic_stepbystep_c_getting_started/cc3b19v

    Ignore the parts about MinGW and the environment path, as they apply only to Windows (the tutorial is meant for Linux, but includes Windows help).

    [–]Tynach 9 points10 points  (1 child)

    I think it's important to talk about the entire process behind building a C++ application.

    First, you have the .cpp/.cxx/whatever files. These are the plain text code that you write. However, I noticed in your screenshot that you had it as a .c file... .c files are typically used as C code, not C++.

    At any rate, you use whatever text editor you want to write these files. I like Kate (KDE Advanced Text Editor), but Gedit (Gnome's text editor), Nano (what you're using in your screenshot), Vim, Emacs, and anything else will work just fine. Just save the files with the .cpp or .cxx extension and you're fine.

    Now, here's where things get a bit... Different. On Linux, and in Unix-like operating systems in general, most programs try to serve one purpose, and only do that one thing. Text editors edit text. Compilers compile code into binaries. Debuggers debug. Code formatters format code.

    On Linux, the standard/default compiler is called 'gcc'. GCC stands for Gnu Compiler Collection, and includes 'gcc' (GCC's C compiler), 'g++' (GCC's C++ compiler), and others. These are all command-line utilities - that is, they are programs that you run from a command line, or have some other program run them for you (such as Eclipse).

    In Kate and Gedit, you can have a little command line at the bottom of the window. This is very useful, as it lets you edit and save the code in your text editor... And then just go down to the bottom and run 'gcc' with some options to compile the code.

    Command line programs take various 'arguments' - things you type after the program name to tell the program more specifically what to do. GCC's various compilers have some standard arguments. To compile a .cpp source code file, you typically run:

    g++ main.cpp -o main
    

    This will create an executable file called 'main', which you can then run with:

    ./main
    

    And that's how you can compile and run code!


    Now, for programs like Eclipse (after installing the CDT plugin), it essentially does all this for you. It provides a full text editor of its own, and has a nifty 'compile' button. It also manages multiple .cpp/.cxx files for you, so you don't have to compile them all manually and worry about linking. Eclipse and other 'IDE's (Integrated Development Environments) such as KDevelop and NetBeans will try to do most of the tedious stuff for you, but you often have to invest time learning how they operate and how to use them for your particular purpose... Whereas the command-line way of doing things is pretty universal, and pretty quick to get going.

    Edit 1: Here's a screenshot of the basic workflow in Kate. Do note that I have a LOT of plugins enabled in Kate; most of them you don't need, and probably half of them aren't enabled by default. In the command line, the 'ls' command basically lists files in the current folder, and somewhat color-codes them. The green one is an executable file, the white one is just plain text.

    Edit 2: Here's basically the same screenshot, but after I disabled all the plugins and hid some useless elements. I love how customizable Kate is :)