Saturday, May 1, 2010

Compile 1st C++ Program in Ubuntu

Having installed Ubuntu for quite a long time, and I finally have learnt how to program C++ in this Unix environment. 

I type my C++ program using gedit that is available under Ubuntu.
I tried this code first hand and it does not worked.

$ gcc -o  hw1 hw1.cpp

I found out the reason is that gcc is used for only C program files and not C++. The following command is actually worked out.

$ g++ -o  hw1 hw1.cpp

This -o basically used to suggest name for the executable file that g++ would create. In case if you typed something like the following:

$ g++ hw1.cpp

You would be having a a.out in the same directory as the source C file. This is the default name of the executable that g++ creates. This would create problems when you compile many programs in one directory. So you override this with the -o option followed by the name of the executable.

Would create an executable by the name hw1 for your source code named hw1.cpp.

Running the executable that you created is as simple as typing the following at the prompt.

$ ./hw1
$ ./a.out

Or whatever you named your executable. 


72haughn0z said...

Such software is used to design components for digital manufacturing technologies, including 3D printing and CNC machining, in fields similar to aerospace, healthcare, and client products. CAD software additionally be|may additionally be|can be} used to create 3D models for digital-only functions similar to 3D animation and video video games. Spacecraft are even more complex than airplanes and have the added Portable Washer Dryer drawback that they're "manufactured" in tiny quantities—sometimes just one is ever made.

Post a Comment