PDA

View Full Version : gcc in terminal




raiderz182
Jan 16, 2004, 05:32 PM
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



jamesrw
Jan 16, 2004, 06:03 PM
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

raiderz182
Jan 16, 2004, 06:22 PM
this is the error i get :

Macintosh:~/desktop Mike$ gcc asdfasdf.cpp
ld: Undefined symbols:
std::basic_istream<char, std::char_traints<char> >::operator>>(int&)
std::basic_ostream<char, std::char_traits<char> >::operator<<(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::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)
___gxx_personality_v0

Doctor Q
Jan 16, 2004, 06:50 PM
What #include lines does the program use?

You could check this thread (http://forums.macrumors.com/showthread.php?s=&threadid=55685) in case it helps.

raiderz182
Jan 16, 2004, 06:56 PM
i've tried
#include <iostream>
using namespace std;

and

#include <iostream.h>

#include <iostream.h>
using namespace std;

Doctor Q
Jan 16, 2004, 08:09 PM
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.

Nermal
Jan 16, 2004, 11:46 PM
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.

NuPowerbook
Jan 17, 2004, 02:33 PM
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.