Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I have just switched my programming platform from Win9X to Linux. First, I wrote a simple test program (T1.cpp)#include
int main(int, char**)
{
cout succeeds (T1.o is created)
$ gcc -o T1 T1.o
Then, I got the error messages
1.undefined reference to cout
2.undefined reference to 'ostream::operator<<(char const*)'Looks like the compiler (I am using GNU C++ compiler ver.2.95.3) did not find the libraries for stream classes. Where are they? As I searched the web, it looks like I need glib++ but I wasn't able to find it either on my PC or on the web.
Thanks in advance.

I noticed that part of my previous message was lost. The program is as follows:
#include
int main(int, char**)
{
cout << "Test program\n";
return 0;
}compilation:
$ gcc -c T1.cpp
This succeeds (T1.o is created)$ gcc -o T1 T1.o
Fails (error messages are as above)

Hi!
it still did not display right. You can use the code converter that you can download from the main "programming" forum page, in order to display nicer code.
So I don't now which header you were trying to include.
You're supposed to include iostream.h.you could have gone to google, and typed "cout header file #include" in the search box. It would have led you to iostream.h
Now if you WERE using iostream.h, I think I cannot be of great help. You should try to include "iostream" (*without* the ".h"). I heard some people speaking about that.
- Hope it helps -

Well, sorry.
It might be, as you seem to think, a problem with making the compiler aware of your libraries.
But shouldnt it then send an compiler error "cannot open include file", or something?
If not, I don't know. Sorry

Hi!
Looks like you are mixing a bit of c and c++.
Try using std::cin or just add "using namespace std" to the top of your program.
/Marcus

What about including iostream.h ?
#include
int main() {
cout << "foo" << "bar" << endl;
return 0;
}If it compiles, but doesn't link, you should check, if you have and are using all libraries needed. I dunno, which of them you need under Linux, but on most distributions this should link well.

Thanks for your replies. And Gauthier, thanks again for letting me know of the coder.exe. I hope my code will appear properly this time.
I am including iostream.h in my sample program.
#include <iostream.h>int main(int, char**)
{
cout << "Test program\n";
return 0;
}After reading your replies, I have tried the followings:
1. adding "using namespace std" at the beginning of the program
2. using std::cout instead of cout
3. replacing iostream.h with iostream
None worked. The linker still returns the error message "undefined reference".Looks like I do not have the class library. If anyone can compile C++ codes which use stream classes in Linux, I would like to know what version of gcc s/he is using, and if s/he has glib++ and where s/he has gotten it. Thanks in advnce,

Hi all,
It turned out to be a very simple mistake. I should have used g++ instead of gcc. I got the clue from http://ricardo.ecn.wfu.edu/glib-linux-archive/0006/0031.html.
Thanks again for all your help!!

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |