Hi,

I am using Fedora core 5 32 bit Linux. Just wrote this small C++ prgram and saved it as test.cpp on the desktop and then tried to compile it using the terminal with the following command

gcc test.cpp - o test

but it is showing the following message as the ouput,

gcc test.cpp -o test 
/tmp/ccYvtTgk.o: In function `__static_initialization_and_destruction_0(int, int)':test.cpp:(.text+0x23): undefined reference to `std::ios_base::Init::Init()' 
/tmp/ccYvtTgk.o: In function `__tcf_0':test.cpp:(.text+0x6c): undefined reference to `std::ios_base::Init::~Init()' 
/tmp/ccYvtTgk.o: In function `main':test.cpp:(.text+0x8e): undefined reference to `std::cout' 
:test.cpp:(.text+0x93): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)' 
:test.cpp:(.text+0x9a): undefined reference to `std::cin' 
:test.cpp:(.text+0x9f): undefined reference to `std::basic_istream<char, std::char_traits<char> >::get()' 
/tmp/ccYvtTgk.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' 
collect2: ld returned 1 exit status 
You have new mail in /var/spool/mail/root

Can't figure out what is the cause here. Help please. Thanks.

bad link -- either fix the link or post the code. My guess is that you either used an old header file or no header file at all. should be <iostream>, not <iostream.h> (doesn't have a .h extension)

bad link -- either fix the link or post the code. My guess is that you either used an old header file or no header file at all. should be <iostream>, not <iostream.h> (doesn't have a .h extension)

This is the code written in the Kate text editor and saved as test.cpp

#include <iostream>

using namespace std;

int main()
{
  cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
  cin.get();
}

Thanks..

what version of gcc do you have? The program looks ok to me. Maybe you need to upgrade to Fedora 6 which will also upgrade your compiler.

>>undefined reference
that usually means you need to specify the c++ libraries on the command line.

gcc test.cpp lib<archive name here>.a -o test

try this:
g++ test.cpp -o test

There is some bug with the terminal that makes using the alternate invokation of gcc neccessary. I think the g++ forces C++.

Oddly, I can run a shell command from the Vim editor (running in a terminal) and the gcc will work fine.

If you don't use Vim, then disregard the following...

to compile (from Vim)
:! gcc test.cpp -o test
or
:make test (assuming that test.cpp is the current file)

to run
:!./test
to debug
:! gdb ./test

Compared to the very good IDE's that are available, the command line version of gdb is primative and inconvienient at best.

Why don't you get the linux version of code::blocks?
Works great!

try this:
g++ test.cpp -o test

There is some bug with the terminal that makes using the alternate invokation of gcc neccessary. I think the g++ forces C++.

Oddly, I can run a shell command from the Vim editor (running in a terminal) and the gcc will work fine.

If you don't use Vim, then disregard the following...

to compile (from Vim)
:! gcc test.cpp -o test
or
:make test (assuming that test.cpp is the current file)

to run
:!./test
to debug
:! gdb ./test

Compared to the very good IDE's that are available, the command line version of gdb is primative and inconvienient at best.

Why don't you get the linux version of code::blocks?
Works great!

Thanks for the help, it works now with g++. Good.

This question has already been answered. Start a new discussion instead.