GNU Emac C++ Programming??

Pages: 12
If it is possible?

Can anybody give me a quick tutorial on how to write, compile, and run code using a GNU Emacs. I'm trying to get into Linux. Any help would be greatly appreciated.

Thanks,
AppDevTrainee
It's very possible, but if you're just starting out, it might be easier to just use emacs to write your source code and manually use gcc to do the compiling. emacs isn't a C++ compiler itself; when used as an IDE it usually makes use of whichever compiler you suggest.

It's my text editor of choice for coding, and I just use it to write the source and use makefiles to compile it all.

As for running the code; again, just type the program name at the command line.
okay thank you :) next question, because im just starting out on linux. Do i just download a gcc compiler or does Linux have some kind of embedded compiler or something?
Linux does not inherently come with a compiler. However, people generally don't get Linux so much as one of the distributions thereof; for example, Ubuntu or Fedora. Many distributions come with a compiler, usually the GCC, already bundled.

PPick your distribution of choice and install it. If it doesn't come with GCC, getting it is generally astonishingly easy. For example, on ubuntu, it's installed with the command

apt-get install gcc

at the command line, or by opening the Synaptic package manager and ticking the box next to GCC. It's astonishingly easy.
Last edited on
thank you. yeah im about to dual boot my laptop with linux, and im thinking about getting Mint on it. Or mayb Ubuntu, butwhen i do i will def follow those instructions to get myself started. any further advice??
Something that always confuse me is gcc is a C compiler, then g++ is a C++ compiler ? And both usually come bundled with Linux distribution correct ?
GCC used to mean Gnu C Compiler, but very shortly after it was born it became the GNU Compiler Collection, as it supports a lot more languages than just C. G++ is the common command people use to run the GCC with the language set to C++.

To say they usually come bundled with a Linux distribution is probably true of the more mainstream distributions like Ubuntu and Fedora. There are, of course, a bazillion Linux distributions; do the majoirty come with GCC? No idea.
Thanks for clearing my doubts. I still thought gcc and g++ are *separate* compilers. One is for C and the other is for C++.

So you mean to say g++ is actually gcc with language set to C++. Now why invent a new name g++? Why not say gcc -lang cpp or other command line options so then why ppl use they know it is actually invoking gcc but turn on the C++ language feature in it isn't it ?

But g++ is shorter to type so let's keep it that way :P
*Fart noises*

did someone just say emacs?

I use gvim

go ahead an open a terminal and type in vimtutor
why do more work sohguanh... seriously. typedef is the same thing and it actually helps a lot with large scopes etc

You're also better off saying GNU/Linux. Linux is simply the kernel in the OS. Nothing more. Gnu is the the unbelievable userland, that's the things running in userspace, tools that come with Linux. Linux is a great kernel though. I look at stallman as a hero though.
Last edited on
okay another question. can somebody give me general directions on how to run code using an emac. well not really that, but more of how to get the code to the compiler lol. i know this sounds very elementary, but its linux, not necessarily my area of expertee. im a rookie in this environment.
Write some code. The code is a text file. Let's say it's named code.cpp because when you saved the file that's what you named it.

Now, in the directory containing code.cpp, type the command

g++ code.cpp

The compiler will go to work and if it works, present you with an executable, probably named a.out

You can then run that executable with the command

./a.out
do i type G++ code.cpp in the terminal?? what do your mean type it in the directory?
nevermind i got it working :) thanks
Ok I am curious again, ever wonder why the default compiled executable by gcc/g++ is always named a.out ? I was guessing the original developers of gcc/g++ are lazy ppl and they feel a single character a follow by a extension .out is enough. How imaginative naming :P
Thanks for link. Now I know a.out is a file format. May I know what is FTW ?
It stands for "For the win." "X FTW" means something like "X is awesome" or "X rocks."

Oh awesome, wiktionary has an entry on it: http://en.wiktionary.org/wiki/for_the_win
Last edited on
Don't use emacs... gVim FTW!
@ascii.....if its better than emacs, i will def be willing to try it out
Pages: 12