gcc, c++ compiling problems

Discussion in 'Mac Programming' started by davidlt, Aug 29, 2007.

  1. macrumors member

    Joined:
    May 22, 2007
    Location:
    Lithuania
    #1
    naujas.cpp:
    Code:
    #include <iostream>
    
    int main()
    {
       std::cout << "Hello World!";
       return 0;
    }
    of course you can use "using namespace std;" and you don't need to write like this std::cout.

    Compiling:
    Code:
    gcc -o naujas naujas.cpp
    Problems:
    Code:
    macbook:~/sandbox marius$ gcc -o naujas naujas.cpp
    /usr/bin/ld: Undefined symbols:
    std::ios_base::Init::Init()
    std::ios_base::Init::~Init()
    std::cout
    std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
    ___gxx_personality_v0
    collect2: ld returned 1 exit status
    
    For my eyes it looks like the problem is with std library, but I don't know much about C++. Any ideas how I could compile it? I would like to find out, I will be programming in C/C++ in University using Debian/Solartis.

    By the way, I can compile C code with gcc using Mac.
     
  2. macrumors newbie

    Joined:
    Mar 7, 2006
    Location:
    Sacramento, CA
    #2
    Try using g++ instead of gcc
     
  3. thread starter macrumors member

    Joined:
    May 22, 2007
    Location:
    Lithuania
    #3
    Worked just perfect, thanks for this one. But why gcc can't compile C++ code?
     
  4. macrumors 68020

    pilotError

    Joined:
    Apr 12, 2006
    Location:
    Long Island
    #4
    because g c c = gnu C compiler
     

Share This Page