
-----------------------------------
saltpro15
Thu Feb 12, 2009 3:36 pm

Compiling in Linux
-----------------------------------
so I started some programming in Ubuntu, got a great IDE called anjuta, and I just have some questions, call it a learning experience instead of just hitting  a button.  Why are files .cxx and not .cpp? how does compiling work, since linux can't run .exe's?

-----------------------------------
Insectoid
Thu Feb 12, 2009 3:44 pm

RE:Compiling in Linux
-----------------------------------
I believe ubuntu comes with G++, though I'm not sure. I know you can compile from the terminal, for example, to compile C++, type G++ . Make sure to navigate to the right folder with the cd command. for interpreted languages or java, type .  For example, 

>> ruby example.rb

will execute the file example.rb through the ruby interpreter.

-----------------------------------
saltpro15
Thu Feb 12, 2009 3:45 pm

RE:Compiling in Linux
-----------------------------------
ah, thanks, just trying to wrap my head around this

-----------------------------------
DemonWasp
Thu Feb 12, 2009 4:09 pm

RE:Compiling in Linux
-----------------------------------
It doesn't matter so much what your files are called, as there are a few extensions that C++ allows, including .cxx, .cpp, .c, .cc, .C and so on. I'm not aware of any real distinguishing factor, save that C++ should be .cpp or .cxx while C should be .cc or .c .

Just try something like:
g++ file.cpp -o executableName

With your own file substituted in. You can skip the -o executableName bit; if you do, it defaults to "a.out".

You are correct that Linux cannot run .exe files, as those are Windows-specific compiled files. However, UNIX operating systems do have their own binary executable format. These files are identified by the file contents as well as by the permissions on the file rather than by the extension (you must have "execute permission", and the OS must know how to execute the file - it knows how to execute shell scripts and compiled code, for example).

Here's an example of compiling a simple program:

file.cpp

#include 
int main ( int argc, char ** argv ) {
    std::cout 