Re: Standard library confusion

From: Jeff Schwab (jeffplus_at_comcast.net)
Date: 02/29/04


Date: Sun, 29 Feb 2004 08:03:48 -0500

Walkaway Renouf wrote:
> I'm about to try to teach myself C++ and have a couple of books on order
> from Amazon. But I'm the impatient type, and while I'm waiting for them
> to arrive, I figured I'd find what I can on the web. The problem is,
> this has led to a little confusion (not surprising really).
>
> I'm using SuSE 8.2. I have a couple of compilers at my command - g++ and
> gcc.

Those are compilers for two, different languages: C++ and C, respectively.

> It would seem that g++ uses library files such as <iostream>

Right, that's a standard C++ header.

> which, if I
> understand correctly, is the older style of doing things.

It's the newer style. Old C++ headers looked like the C headers, so
this one was called <iostream.h>. The newer, ISO standard header is
<iostream>.

> When using
> gcc, I use something like <stdio.h>, which is part of the current
> standard library - is that right?

That's part of the standard C library.

> Now, gcc looks for its standard library files in /usr/include/ and g++
> looks in /usr/include/g++/ - which is all very well, but is it possible
> to mix the two?

Sorta. :) The C++ library includes its own versions of the C headers,
with the ".h" removed and a "c" prepended. So, the C++ equivalent for
<stdio.h> is <cstdio>.

> The reason I ask is that the programs I want to write
> will probably involve MySQL databases, so I want to use the MySQL++ API.
> This, although it claims to be compiled for the gcc compiler, seems to
> use things like <iostream>.

The "gcc" compiler is a C compiler. GCC (all caps) is the Gnu Compiler
Collection, including both gcc and g++.

> To confuse things further, it wants MySQL
> header files which are in /usr/include/mysql/. The compilers don't
> appear to look in there when they encounter:
> #include <mysql.h>

Use the -I command-line option to g++. E.g:

   g++ -I/usr/include/mysql my_cplusplus_source_file.cc

> So here are some specific questions (I have googled on these to some
> extent, but have had trouble getting straight answers):
>
> * If, say, gcc is configured to look in /usr/include/ for header files,
> will it automatically look in sub-directories too?

No.

> * If not (as I suspect), should I change gcc's configuration to include
> any sub-dirs I want to use - such as /usr/include/mysql/?

No, use a Makefile to set that stuff up for an individual project. Gnu
provides a very fine "make" utility to work with its compilers.

> * Would it be sensible to also change gcc's config to look in
> /usr/include/g++/ in case it encounters older-style headers in API or
> other header files? Or might this lead to other problems?

No. When you use g++, the standard header directory will be searched
automatically. When you use gcc, you do not want it to look at C++
header files.

> Any help would be appreciated.

Good luck!



Relevant Pages

  • Re: Header Files and Interfaces Yet Again
    ... compiler is not allowed to read them. ... illustrate the difference of header file and fake header. ... fake headers can not serve as sufficient information to the ... > something but it appears to me the Standard Library is not designed ...
    (comp.lang.cpp)
  • Re: non-standard functions in libc -- bad design?
    ... standard supported by a compiler/library, ... I'd call them extensions. ... gcc doesn't get a vote. ... gcc is just a compiler, ...
    (comp.lang.c)
  • Re: c standard
    ... *particular* compiler and therefore off topic in this newsgroup. ... you wanted to see this amusing response you should have tried to ask ... standard that gcc supports, the -ansi notwithstanding, and its probably ...
    (comp.lang.c)
  • Re: Header Files and Interfaces Yet Again
    ... >> headers to feed to the compiler. ... But he actually uses what you call a fake header. ... I'm not really srue why header files that present things that aren't ... >> something but it appears to me the Standard Library is not designed ...
    (comp.lang.cpp)
  • THREATCON --> Re: [Full-Disclosure] scriptkids on this list
    ... Does anyone think something like hints for compiler should be more ... it wold be nice to have something like this in gcc standard ... #define NORETURN ...
    (Full-Disclosure)