Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

raiderz182

macrumors regular
Original poster
Oct 17, 2003
141
0
north philly
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
 
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
 
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
 
i've tried
#include <iostream>
using namespace std;

and

#include <iostream.h>

#include <iostream.h>
using namespace std;
 
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.
 
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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.