LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to compile c++ programs in centos version (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-compile-c-programs-in-centos-version-4175453910/)

anbarasi 03-13-2013 09:23 AM

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.....

johnsfine 03-13-2013 09:33 AM

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.

fortran 03-13-2013 09:41 AM

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

netnix99 03-13-2013 09:48 AM

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)

anbarasi 03-13-2013 10:58 AM

Quote:

Originally Posted by netnix99 (Post 4910781)
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..!!

johnsfine 03-13-2013 12:31 PM

Try
yum install gcc-c++

Quote:

Originally Posted by netnix99 (Post 4910781)
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 (Post 4910827)
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.

knudfl 03-13-2013 01:27 PM

No, # yum install gcc

... will install gcc only.

netnix99 03-13-2013 02:35 PM

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.

John VV 03-13-2013 11:24 PM

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"


eklavya 03-14-2013 01:05 AM

Quote:

Originally Posted by pavi_kanetkar (Post 4910777)

The link is dead.

jpollard 03-14-2013 07:46 AM

Quote:

Originally Posted by netnix99 (Post 4910781)
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.

anbarasi 03-14-2013 09:28 AM

thanks
 
Quote:

Originally Posted by johnsfine (Post 4910868)
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!!


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