www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/01/01:17:10

From: John Wong <johnw AT ecs DOT school DOT net DOT hk>
Newsgroups: comp.os.msdos.djgpp,comp.lang.c++
Subject: Undefined cout?
Date: Tue, 1 Apr 1997 11:54:47 +0800
Organization: Hong Kong School Net
Lines: 40
Message-ID: <Pine.LNX.3.93.970401115203.12541B-100000@ecs.school.net.hk>
Reply-To: John Wong <johnw AT ecs DOT school DOT net DOT hk>
NNTP-Posting-Host: ecs.school.net.hk
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I've got a question about DJGPP installation.  Now I've just installed 
DJGPP 2.0, and find the following program doesn't compile:

#include <iostream.h>

class X {
	int val;
public:
	X() {val = 0;}
	X(int i) {val = i;}
	void func() const { cout << val << '\n'; }
};

main()
{
	X v1;
	v1.func();
	X(3).func();
	return 0;
}

gcc returns the following statements:

test.cc(.text+0x5e): undefined reference to `cout'
test.cc(.text+0x63): undefined reference to `ostream::operator<<(int)'
test.cc(.text+0x6e): undefined reference to `ostream::operator<<(char)'

It seems to be a problem with g++, since when I replace iostream.h with
stdio.h and cout with the C-style printf, everything's alright and the
program runs as expected.

What's wrong with my g++ installation (or even my code)?  How to install
DJGPP correctly?

Any help would be much appreciated.


John


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019