run a C++ program from terminal
Linux doesn’t have extensions … it’s not a brain dead OS like Windows, at least not when it comes to actually developing anything.
To make life easy, however, there are certain conventions.
If I have a c++ source file called foo.cpp and I run
gcc -c -Wall -g foo.cpp
The program gcc will understand that foo.cpp is a C++ source file (not a fortran, C or java source file) and generate an object file with the extension .o
If I then do:
gcc -g -L/usr/lib -lstdc++ foo.o
gcc will understand that i intend to invoke the linker (ld) and use libstdc++.so in the /usr/lib directory, also — add debugging symbols.
Because I didn’t specify a target, gcc will produce a file a.out and set executable permissions on it.
On the other hand I can specify a target with gcc:
gcc -g -L/usr/lib -lstdc++ foo.o -o foo.xxx.blah
It makes no difference what I call the compiled binary executable, linux could care less.
Of course, for a simple program, I would skip the intermediate object:
gcc -g -Wall -lstdc++ foo.cpp -o foo
and now gcc understands that I want to compile a c++ source file, link it to the system’s standard c++ shared object and put the result (with debugging symbols) in a file called foo.
Or I can make my life even easier:
g++ -g -Wall foo.cpp -o foo
g++ is a program that does everything gcc did in the example above, but it only deals with c++ code and linkage.
Like us on Facebook
We need your assistance to stay live
This week Top Posts
- Top Things To Do After Installing Ubuntu 13.10 'Saucy Salamander' : Ubuntu 13.10 Saucy Salamander will be released on coming October 17th with many new salient featur...0 comments |
- Install Fail2Ban On Ubuntu Server 13.04/13.10 : Introduction Fail2Ban is an intrusion prevention framework written in the Python programming l...0 comments |
- 5 Android Apps that’s Going to Make Running Your Business Less Stressful : Running a business can be very stressful. You have to think about team collaboration, making sure th...0 comments |
- Install Crashplan backup tool in Linux : CashPlan is an automated backup solution that either uses the CrashPlan Central server or any other ...0 comments |
- install Git in Ubuntu : Git is a distributed revision control system with an emphasis on speed. Git was initially designed a...0 comments |
- Install Corosync and Pacemaker On CentOS 6.5 : I will show you in this tutorial how to install your first cluster Corosync and the Linux Cluster Ma...0 comments |
- Install Uget Download Manager In Ubuntu, Fedora, Debian
- Download Elementary OS ‘Luna’ Official Wallpapers
- Install Power Commands 0.1.5 On Ubuntu 14.04/13.10/12.10/12.04
- 5 Android Apps that’s Going to Make Running Your Business Less Stressful
- Puppet agent Install Using Script
- Install Corosync and Pacemaker On CentOS 6.5
- Install Fail2Ban On Ubuntu Server 13.04/13.10
- How To Install Google Chrome in Fedora 20, 19, 18
- How to surf using Tor Browser Bundle
- New Games got Greenlit on Linux by Steam Today!
This work by unixmen.com is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Copyright © 2008-2013 Unixmen.com .