gcc in terminal

Discussion in 'Mac OS X 10.3 (Panther) Discussion' started by raiderz182, Jan 16, 2004.

  1. raiderz182 macrumors regular

    Joined:
    Oct 17, 2003
    Location:
    north philly
    #1
    ok i am very new to this...
    i have a text file that i saved and then renamed it to asdfasdf.cpp instead of asdfasdf.txt
    and then i write my c++ code in there and i go to the terminal and i type gcc asdfasdf.cpp
    is there something i didnt do? because i know for sure the program works and i am at the write directory and everything.... please help
     
  2. jamesrw macrumors newbie

    Joined:
    Dec 17, 2003
    #2
    hmm, gcc <filename> compiles the program (presuming you have the dev tools installed)

    this creates a file named a.out which is the executable

    type ./a.out at the terminal to run the program
     
  3. raiderz182 thread starter macrumors regular

    Joined:
    Oct 17, 2003
    Location:
    north philly
    #3
    this is the error i get :

    Macintosh:~/desktop Mike$ gcc asdfasdf.cpp
    ld: Undefined symbols:
    std::basic_istream<char, std::char_traints<char> >::eek:perator>>(int&)
    std::basic_ostream<char, std::char_traits<char> >::eek:perator<<(int)
    std::ios_base::Init::Init[in-charge]()
    std::ios_base::Init::~Init [in-charge]()
    std::cin
    std::cout
    std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
    ___gxx_personality_v0
     
  4. Doctor Q Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #4
    What #include lines does the program use?

    You could check this thread in case it helps.
     
  5. raiderz182 thread starter macrumors regular

    Joined:
    Oct 17, 2003
    Location:
    north philly
    #5
    i've tried
    #include <iostream>
    using namespace std;

    and

    #include <iostream.h>

    #include <iostream.h>
    using namespace std;
     
  6. Doctor Q Administrator

    Doctor Q

    Staff Member

    Joined:
    Sep 19, 2002
    Location:
    Los Angeles
    #6
    I didn't read carefully enough. I see that you got link-time errors, not compile-time errors. Sorry to steer you wrong.

    I'd check the man page for gcc and see what switches or environment variable you need to set so it knows where the libraries you're using reside.
     
  7. Nermal Moderator

    Nermal

    Staff Member

    Joined:
    Dec 7, 2002
    Location:
    New Zealand
    #7
    I've found that the easiest thing to do is just open up Xcode and create a new "C++ Tool". This will make a console app, and will automatically pass the right commands to gcc.
     
  8. NuPowerbook macrumors member

    Joined:
    Jan 17, 2004
    #8
    You have to use the g++ tool from the command line in order to compile a C++ program. So do this from the command line:

    g++ asdfasdf.cpp -o program_name

    then to run it type:

    ./program_name

    Also, you want to use this include:

    #include <iostream>
    using namespace std;

    iostream.h has been depreciated, so it no longer works.
     

Share This Page