8

I want to compile a C++ program in Arch Linux, but there's no "g++" package as there is in Ubuntu repositories for example.

Using -x too won't work. like this:

gcc -x c++ -o myprog myprog.cpp
8

gcc is both a C and C++ compiler.
It will look at the file's extension and process accordingly.
g++ is only a wrapper that calls gcc
g++ is installed with the gcc package in Arch

gcc file.C # uppercase .C (or .cpp) will process as C++ 
gcc file.c # lowercase .c will process as C
  • Though I have gcc on my Arch, there's no g++, and though my file is prog.cpp and I also use -x c++ I should tell you it only works in case I also add -lstdc++, which correctly compiles. Do you suggest this method? (gcc -x c++ -o myprog -lstdc++ myprog.cpp) – Haix64 Mar 21 '12 at 12:19
  • if you use std c++ in your code then yes, you need to link (-lstdc++) with the std c++ library. I've installed gcc on my arch and g++ is present. It should be in /usr/bin, I don't believe the -x c++ is needed if file extension is .cpp, gcc should select on that – bsd Mar 21 '12 at 13:13
  • 1
    g++ should be part of the gcc package. Have you tried reinstalling gcc? – Craig Mar 21 '12 at 16:56
  • 1
    g++ is part of the gcc package – bsd Mar 21 '12 at 20:09
  • You gotta be right Craig. I had not installed the gcc manually, since I thought having access to gcc should mean that I've got the whole package on system, but pacman shows me there's 18MB to download for the gcc package. I haven't done it yet but I'm sure it works as soon as I do it. Thanks for your helps, Craig and bdowning. – Haix64 Mar 23 '12 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.