LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-13-2013, 10:23 AM   #1
anbarasi
LQ Newbie
 
Registered: Mar 2013
Location: bangalore
Posts: 13

Rep: Reputation: Disabled
how to compile c++ programs in centos version


i am using linux-centos system to write c++ programs,but there is a problem with the compiling command.i use g++...command.but get an err msg "cammand not found"...can someone help me to understand why is the compiling command not responding in centos version. but the same command compiles in the open suse version.is it possible the compiler not to be installed properly in centos.pls explain.....
 
Old 03-13-2013, 10:33 AM   #2
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181
You need to install some packages. I think everything you need is included in the group of packages installed by the following command (as root):

yum groupinstall 'Development Tools'

I don't currently have admin rights on any Centos system, so I can't check whether I got the syntax of that command right or whether there are any header or library files you will also need that might not be included in that group.

If you google the command I suggested, you will see lots of pages that explain what it includes. Those pages probably will give you other info you will need.

Last edited by johnsfine; 03-13-2013 at 10:36 AM.
 
1 members found this post helpful.
Old 03-13-2013, 10:41 AM   #3
fortran
Member
 
Registered: Nov 2011
Location: Cairo, Egypt
Distribution: CentOS, RHEL, Fedora
Posts: 300
Blog Entries: 2

Rep: Reputation: 51
Have you checked, gcc is installed properly or not. If it is installed properly
Check gcc version using
Code:
gcc -v
To compile C program on Linux terminal

1) Write any C program in text editor and save as filename.c
In following example, I have saved this file on my Desktop.

2) To run this program, you have to compile it first.

Code:
$ gcc -o compiled-filename /home/user/Desktop/filename.c
Where compiled-filename is the name of compiled file, it can be anything.
This will generate a compile copy of your program as a name compiled-filename in same directory where you ran the above command.

3) Now create output copy of your program.
Following command generate a output file of your program in same directory.

Code:
$ gcc /home/user/Desktop/filename.c
4) Now run your program.

Code:
$ ./a.out 
 or 
$ ./compiled-filename
where a.out is output copy of your program.
Alternatively you can run compiled copy of your program.

Example:
http://2.bp.blogspot.com/-24QssOXJ0z...0/Untitled.png
 
Old 03-13-2013, 10:48 AM   #4
netnix99
Member
 
Registered: Jun 2011
Distribution: redhat, CentOS, OpenBSD
Posts: 298

Rep: Reputation: 98
You can also do a
Code:
 yum install gcc
and just install gcc, rather than all of the development tools. (This will install c++ also)

Last edited by netnix99; 03-13-2013 at 10:50 AM.
 
Old 03-13-2013, 11:58 AM   #5
anbarasi
LQ Newbie
 
Registered: Mar 2013
Location: bangalore
Posts: 13

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by netnix99 View Post
You can also do a
Code:
 yum install gcc
and just install gcc, rather than all of the development tools. (This will install c++ also)
hey i did use yum install gcc!!
after tat only am getting da error..!!
 
Old 03-13-2013, 01:31 PM   #6
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181
Try
yum install gcc-c++

Quote:
Originally Posted by netnix99 View Post
install gcc, rather than all of the development tools. (This will install c++ also)
Are you sure installing gcc installs g++ ?

I don't know Centos packages at that level of detail myself. So I did a google search, finding several places claiming the command I showed above is needed, implying the command you suggested is not enough.

Quote:
Originally Posted by anbarasi View Post
after tat only am getting da error..!!
I'm still trying to help anyway. But you should know posts like the above are considered rude in this forum. Show some effort in asking your questions (type whole words) so we don't feel insulted that you expect our effort in answering them.

Last edited by johnsfine; 03-13-2013 at 01:39 PM.
 
2 members found this post helpful.
Old 03-13-2013, 02:27 PM   #7
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2016, Slack14.1 Deb Jessie, + 50+ other Linux OS, for test only.
Posts: 16,276

Rep: Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156Reputation: 3156
No, # yum install gcc

... will install gcc only.
 
Old 03-13-2013, 03:35 PM   #8
netnix99
Member
 
Registered: Jun 2011
Distribution: redhat, CentOS, OpenBSD
Posts: 298

Rep: Reputation: 98
If you have gcc installed, use
Code:
 yum install cpp
On Red Hat, yum install gcc prompts to install all of the following**:
gcc
cloog-ppl
cpp
glibc-devel
glibc-headers
kernel-headers
mprf
ppl

I figured centos would do the same....I could be wrong though...

**Some of these may install due to the specific subscriptions that I am using.
 
Old 03-14-2013, 12:24 AM   #9
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 16,990

Rep: Reputation: 2448Reputation: 2448Reputation: 2448Reputation: 2448Reputation: 2448Reputation: 2448Reputation: 2448Reputation: 2448Reputation: 2448Reputation: 2448Reputation: 2448
for gcc and the needed programs the "groupinstall" i have found works best
yes it installs a lot
but there is also a good chance you might also need the gnome development libaries
and the basic dev libs

the packages are not that big so
--- for my SL6.3 install --
Code:
su -
yum grouplist 
--- a LONG list is outputted ----
--- from that install ----
yum groupinstall "Development tools" "Desktop Platform Development"

--- NOT NEEDED BUT NICE --
yum groupinstall "System administration tools"
 
1 members found this post helpful.
Old 03-14-2013, 02:05 AM   #10
eklavya
Member
 
Registered: Mar 2013
Posts: 619

Rep: Reputation: 136Reputation: 136
Quote:
Originally Posted by pavi_kanetkar View Post
The link is dead.
 
Old 03-14-2013, 08:46 AM   #11
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,654

Rep: Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255Reputation: 1255
Quote:
Originally Posted by netnix99 View Post
You can also do a
Code:
 yum install gcc
and just install gcc, rather than all of the development tools. (This will install c++ also)
You don't really want to do that.

Install the development tools group. Without them c++ becomes useless as you won't have the necessary headers for various libraries, or the tools to help manage compilation (autoconf, make,...). Install any development libraries you will need (these are also included in a group).

You CAN install each package separately, but by the time you get everything working (it will take a day or so to find you are missing "yet another...") that you save time by installing the groups.
 
Old 03-14-2013, 10:28 AM   #12
anbarasi
LQ Newbie
 
Registered: Mar 2013
Location: bangalore
Posts: 13

Original Poster
Rep: Reputation: Disabled
thanks

Quote:
Originally Posted by johnsfine View Post
Try
yum install gcc-c++



Are you sure installing gcc installs g++ ?

I don't know Centos packages at that level of detail myself. So I did a google search, finding several places claiming the command I showed above is needed, implying the command you suggested is not enough.



I'm still trying to help anyway. But you should know posts like the above are considered rude in this forum. Show some effort in asking your questions (type whole words) so we don't feel insulted that you expect our effort in answering them.
thanks i got it!!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to update Kernel in centos 5.7 version to centos kernel version 6.2 jayakumar01 Linux - Server 4 09-13-2012 01:49 AM
How to upgrade php from version 5.1.6 to version 5.3.6 on Centos Manpasand Linux - Server 2 08-09-2011 02:54 AM
How to upgrade php from version 5.2.10 to version 5.3.3 on Centos ashlule1 Linux - Newbie 3 10-18-2010 03:55 AM
What would be the most up-to-date kernel version I could compile for CentOS 5.3? neocookie Linux - Kernel 3 02-22-2010 02:43 PM
how to compile c++ programs in centos version dilinjd Linux - General 2 04-08-2007 06:32 PM


All times are GMT -5. The time now is 05:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration