# Linux C++ Using Emacs -- Need compiler

This topic is 4481 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Okay I'm beginning a project in C++ using Emacs (an OpenGL project). I am at a loss of what compilers I have to work with... Obviously I cannot begin with that question looming. I've never programmed C++ in Linux yet, I've been spoiled by Visual Studio the whole time. I feel stupid asking this because I compile programs a lot for installation... It just never clicked in... Any advice would be great.

##### Share on other sites
The standard C/C++ compiler on linux is called gcc. Type "info gcc" for more information.

##### Share on other sites
Before you start any project, here are a few tips.

1) Get familiar with your editor first. Emacs especially. If you don't know a basic understanding of the commands you won't get any work done.

2) Get familiar with the most commonly used gcc options, or at least know where to find them.

3) Introduce yourself to make. You should know how to write at least a simple makefile.

4) Not as important when you're starting, but it will be eventually... gdb.

LiDN is pretty cool too.

1 and 2 are probably the most important, but 3 and 4 will make your life easier.

##### Share on other sites
Yes, I fiddled with Emacs for a few days.

I have gcc, but decided since I found first Intel's C++ Compiler to stick with that. So far the only difference is in calling it, 'icc'.

Makefiles, ugh....
WAsted hours on this one, still wasting time and still cannot get it to work...
I wrote a simple Hello.cpp which is the one-liner HelloWorld app

#include <iostream>
using std::cout

int main()
{
cout << "Hello World";
}

Care to show me a make file to compile this one file.

##### Share on other sites
Makefile tutorial

You usually use makefiles when you have more than 1 file.

##### Share on other sites
When your projects get a little bigger, there are three ways to go:

1) automake -- generates extremely verbose make files for you, based on another syntax; uses recursive make

2) your own make system of custom make files; typically implemented using recursiv e make

3) self-generating, dependency-accurate, non-recursive cross-project make

Needless to say, I champion option 3 :-) I have a few sample make files that make that all "go" on my web site. The extra-cool part of it is that it does automatic dependency tracking (so that all files that include bar.h re-compile when you edit that file) -- that's NOT a standard feature for UNIX make files! And it does this without any pre-process or "makedepend" step! (NOT usually done on UNIX!) And it's fast! (not common among automated, recursive make systems)

Sorry, I'm getting away from myself there...

here's a command line that'll build and link your program using GCC:

gcc -o myprogram main.cpp -lstdc++

##### Share on other sites
I suggest ussing the g++ compiler for C++ programs. Also as far as text editors go, while emacs is fine, I suggest gvim/vim. Its very simple but also has many usefull features. And I couldn't help but notice you are only using cout. It's good practice to using namespace std that way you have access to all the iostream functions. And makefiles are kinda like scripts to do all the compiling for you

##### Share on other sites
use g++ for a c++ program and use gcc for a c program and also javac for java

##### Share on other sites
Quote:
 Original post by nethackproAlso as far as text editors go, while emacs is fine, I suggest gvim/vim.

That's also my choice (I never could get my head around EMACS).
However, today I tried Eclipse's new CDT 3.0.1 (C++ plugin) and it was quite usable, more so than Visual C++ 2005 Express. It features code templates and that is what I am missing most in VC++ 2005 Express/VS 2003.

##### Share on other sites
As someone who uses emacs a lot, I actually suggest not starting with it. The big advantage of emacs is that I work a lot remotely. If you do all your editing on your local system, then the advantages of a console editor diminish a bit.

I highly suggest you start out using a GUI editor ('Kate' is pretty good). Emacs is really quite powerful, but you can get to that later... In the short term, you're going to have enough things getting in your way in such a new and different environment. One less obstacle will lead to a lot less frustation.

Oh, and use gcc. 4.0 is quite nice.

The primary difference between the 'gcc' and 'g++' executables is that 'g++' automatically links against the c++ standard library.

"gcc -lstdc++" == "g++"

##### Share on other sites
Quote:
 Original post by RichardSAs someone who uses emacs a lot, ... then the advantages of a console editor diminish a bit.I highly suggest you start out using a GUI editor ...

Well, emacs is a GUI editor..

Quote:
 Original post by nethackproAnd I couldn't help but notice you are only using cout. It's good practice to using namespace std that way you have access to all the iostream functions.

this is necessarily not true, why "include" the whole namespace when you only need one function?

/Nico

##### Share on other sites
Emacs isn't always a GUI editor... You can run it in a console 'emacs -nw'.
I spent a few days reading and researching Emacs and yes it is a lot to get your head around I am very fond of it already so I'm sticking with it.

Gcc, G++ -- boy did that cause me a problem. None of my C++ Apps would compile, they where spitting out pounds of incomprehensible errors... I switched to g++ and it worked.

My compiler of choice is Intels C++ Compiler for Linux (9.0).

Automake, I couldn't get it to work, apparently it needs some configure.ac file or something???
This makefile stuff seems more than I want to learn right now, I did manage to write a basic makefile to compile a one file project :) I do believe I can take that and use it for any number of files. I'll read that tutorial posted below and see how far it takes me.

3) self-generating, dependency-accurate, non-recursive cross-project make

I'd like that :)

Also, what sort of measures must I take to ensure simply deployability of my end-project across multiple linux distro's?

Thanks,
Halsafar

##### Share on other sites
Quote:
 Original post by HalsafarAlso, what sort of measures must I take to ensure simply deployability of my end-project across multiple linux distro's?

Start by using the compiler included with just about every Linux distribution. At the very least ensure that your programs compile with gcc. Then you can handle multiple compilers with make and friends.

##### Share on other sites
For a simple introduction to the wonderful world of autotools (automake and friends), check out:

It had enough to get me started using it. If thats not enough (or your just a masochist), you can check out the autotools book:
http://sources.redhat.com/autobook/

##### Share on other sites
I'd highly recommend learning to use SCons. It's a lot easier than plain Make, its scripts are a lot simpler, and it can do a lot more. All its build scripts are in Python, so you can do anything you'd do in normal Python.