Thread: gcc not for C++?

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    12

    Question gcc not for C++?

    Hi!

    When writing C++ programs with classes, I get an error with gcc, but g++ and c++ run fine.

    [byt83@CPQNiT Task3]$ ls
    task1.cpp task2.cpp task3.cpp
    [byt83@CPQNiT Task3]$ gcc -lm -o task2 task2.cpp
    /tmp/ccF3VOWt.o(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
    collect2: ld returned 1 exit status
    [byt83@CPQNiT Task3]$ g++ -o task2 task2.cpp
    [byt83@CPQNiT Task3]$ c++ -o task2 task2.cpp
    [byt83@CPQNiT Task3]$

    Any clues, anybody? In an earlier post, gcc is supposed to be a C compiler and not a C++ compiler, but if that's the case, how would somebody explain this:

    [byt83@CPQNiT Task3]$ whatis gcc
    gcc (1) - GNU project C and C++ compiler


    -TiN
    (The iNternet)

  2. #2
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    There is a flag where you can set the language: gcc -x c++ (I believe, though I could be wrong. Check the documentation to be sure.)

  3. #3
    Registered User HaLCy0n's Avatar
    Join Date
    Mar 2003
    Posts
    77
    gcc will work with either or, but if you are going to use C++ programs, you need to specify the language like above, and also to link against -lstdc++. By calling it as g++, it does all of this for you automatically.

  4. #4
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The language specification is unnecessary if the file ends in .cpp, .cxx, .C or .cc, but the linking to the C++ standard library is what causes the errors.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  5. #5
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Posts
    546
    Quote Originally Posted by tin
    [byt83@CPQNiT Task3]$ whatis gcc
    gcc (1) - GNU project C and C++ compiler
    Gcc stands for the GNU Compiler Collection. When you download the Win32 version, for example, you get C, C++, and Fortran 77 (does anybody actually use this part?).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Replies: 4
    Last Post: 09-02-2007, 08:47 PM
  3. Compiles on gcc 3.3 but not on gcc 4.0.3
    By cunnus88 in forum C++ Programming
    Replies: 5
    Last Post: 03-29-2007, 12:24 PM
  4. Resource ICONs
    By gbaker in forum Windows Programming
    Replies: 4
    Last Post: 12-15-2003, 07:18 AM
  5. gcc
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 10-22-2003, 03:46 PM