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
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 |
- Manage Databases And Hosted Servers Remotely With DbNinja : Database administration via command line is bit difficult for newbie system and database administrat...0 comments |
- Setup IT And Asset Management System With GLPI On Debian/Ubuntu : GLPI is the Information Resource-Manager with an additional Administration Interface. You can use it...0 comments |
- How To Configure Linux Clients To Authenticate Using OpenLDAP : This is the continuation of our previous tutorial. In our previous tutorial we learned how to instal...0 comments |
- How To Upgrade From Ubuntu 13.04 Raring To Ubuntu 13.10 Saucy Salamander : Ubuntu 13.10 Saucy will be released on October 17th. Hope it will come with lot of improvements and ...0 comments |
- Install FrostWire 5.6.9 In Elementary OS 'Luna'/ Ubuntu / Linux Mint : FrostWire is a peer-to-peer file sharing program for the gnutella and BitTorrent protocols. FrostWir...1 comment |
- How To Install Linux Kernel 3.12.4 In Ubuntu
- Firefox 26 Has Been Released, How To Install It In Ubuntu And Its Derivates
- How To Install Brasero In Elementary OS ‘Luna’
- Install Sayonara Player In Elementary OS / Ubuntu / Linux Mint
- Manage Databases And Hosted Servers Remotely With DbNinja
- Install FrostWire 5.6.9 In Elementary OS ‘Luna’/ Ubuntu / Linux Mint
- Setup IT And Asset Management System With GLPI On Debian/Ubuntu
- How To Configure Linux Clients To Authenticate Using OpenLDAP
- How To Install Netflix In Ubuntu
- cowsay And fortune Combined Together
This work by unixmen.com is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Copyright © 2008-2013 Unixmen.com .