delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/08/17/08:28:24

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
X-Authentication-Warning: slinky.cs.nyu.edu: pechtcha owned process doing -bs
Date: Sat, 17 Aug 2002 08:28:05 -0400 (EDT)
From: Igor Pechtchanski <pechtcha AT cs DOT nyu DOT edu>
Reply-To: cygwin AT cygwin DOT com
To: cygwin AT cygwin DOT com
cc: =?X-UNKNOWN?B?5bygIOS6rg==?= <johnsonest AT hotmail DOT com>
Subject: Re: [ECOS] why cygwin does not support "iostream.h"?
In-Reply-To: <Pine.GSO.4.44.0208170757370.21909-100000@slinky.cs.nyu.edu>
Message-ID: <Pine.GSO.4.44.0208170816100.21909-100000@slinky.cs.nyu.edu>
MIME-Version: 1.0

On Sat, 17 Aug 2002, Igor Pechtchanski wrote:

> On 17 Aug 2002, Gary Thomas wrote:
>
> > On Sat, 2002-08-17 at 01:03, å¼  亮 wrote:
> > >
> > > hi all,
> > >   my c++ code:
> > >  #include <iostream.h>
> > >   ...
> > >
> > > cout<<value;
> > > ...
> > >
> > > >gcc classtest.cxx -g -o classtest.exe
> > > ld error:
> > >  undefined reference to "cout" and operator "<<"
> > >
> > > how to get iostream's support?
> > >
> >
> > This would be better asked on the CygWin list :-)
>
> This would be better asked on the GCC list :-p
>
> I believe this is in the gcc FAQ.  However, it's been asked often enough
> on this list, so here's an answer for the archives:
>
> gcc uses the file extension to determine the language.  Any extension it
> doesn't recognize is assumed to be a C file.  The default extension for a
> C++ file is ".C".  gcc does not recognize ".cxx", which is used by
> Microsoft compilers, I think.  It is, of course, possible to tell gcc to
> treat a ".cxx" file as a C++ file.  In case you don't want to mess with
> the gcc configuration, use either the "-x c++" option of gcc, or simply
> call g++.
>         Igor

Hmm, I suppose I better correct myself before someone else does...
The default extensions (suffixes) for C++ are ".C", ".cc", ".cpp", and
".cxx".  Any suffix that is not recognized (e.g., ".o" and ".a") is passed
directly to the linker.
However, quoting from the gcc man page:
	Source filename suffixes identify the source language, but which name
	you use for the compiler governs default assumptions:

	gcc	assumes preprocessed (.i) files are C and assumes C
		style linking.
	g++	assumes preprocessed (.i) files are C++ and assumes
		C++ style linking.

Therefore, what happens here is C++-style compilation with C-style
linking.  Using "g++" solves the issue.  Using "gcc -x c++" does not,
since the compilation already recognized the source file as being C++,
it's the linking that's a problem.
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha AT cs DOT nyu DOT edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor AT watson DOT ibm DOT com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

It took the computational power of three Commodore 64s to fly to the moon.
It takes a 486 to run Windows 95.  Something is wrong here. -- SC sig file


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


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