Ask Your Question
1

how to use c++ in fedora?

asked 2014-10-15 15:27:59 -0500

fedora20_user gravatar image

updated 2014-10-15 15:29:38 -0500

I have fedora 20 on my laptop. and C language works without problems, it gets compiled with command [gcc filename.c] but how do I compile it as C++? I just read man gcc and it says I have to save the file with extended name [C, cc, cpp, CPP and some more] but it doesn't work.

And I surely installed gcc-c++ by command sudo yum install gcc-c++

edit retag flag offensive close merge delete

4 Answers

Sort by ยป oldest newest most voted
5

answered 2014-10-15 16:45:06 -0500

vtrefny gravatar image
g++ file.cpp
edit flag offensive delete link more
1

answered 2014-10-15 17:02:20 -0500

dnozay gravatar image

yum install gcc-c++ is indeed correct.

If you are missing dependencies, you can check which packages are missing with repoquery:

$ repoquery --requires --resolve gcc-c++
libmpc-0:1.0.1-2.fc20.i686
gmp-1:5.1.2-2.fc20.i686
mpfr-0:3.1.2-4.fc20.i686
glibc-0:2.18-11.fc20.i686
libstdc++-0:4.8.3-7.fc20.i686
gcc-0:4.8.3-7.fc20.i686
zlib-0:1.2.8-3.fc20.i686
libstdc++-devel-0:4.8.3-7.fc20.i686

create hello.cpp:

#include <iostream>
using namespace std;

main()
{
    cout << "Hello World!\n";
    return 0;
}

then run

$ g++ hello.cpp
$ ./a.out 
Hello World!
edit flag offensive delete link more

Comments

gcc-c++ is the correct package. just see the output of "rpm -ql gcc-c++" and you will see "/usr/bin/g++"

pnemade gravatar imagepnemade ( 2014-10-16 23:42:05 -0500 )edit
1

answered 2014-10-15 16:52:03 -0500

deusdara gravatar image

Hi

Please see that thread

C++ compiler for fedora 20

https://ask.fedoraproject.org/en/question/39177/c-compiler-for-fedora-20/

edit flag offensive delete link more
0

answered 2014-10-16 17:56:16 -0500

SantoshHoropter gravatar image

I suggest after installing by

yum install gcc-c++

you can go for codeblocks if you are a beginner/moderate,

yum install codeblocks

Once there, you can be easy on programs because of awesome sweet gui of the software.

Warning : It makes you super lazy (jk!)

edit flag offensive delete link more

Comments

I didn't mean to take away terminal experience but for most programming purposes codeblocks is great! If you needed to compile simply try cc <filename.cpp> or g++ <filename.cpp></filename.cpp></filename.cpp>

SantoshHoropter gravatar imageSantoshHoropter ( 2014-10-16 18:00:12 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2014-10-15 15:27:59 -0500

Seen: 7,883 times

Last updated: Oct 16 '14