Re: Standard library confusion
From: Jeff Schwab (jeffplus_at_comcast.net)
Date: 02/29/04
- Next message: Chris \( Val \): "Re: Been asked a million times but what's the best book or just use the Internet to learn C++?"
- Previous message: Chris \( Val \): "Re: When to introduce exception safety"
- In reply to: Walkaway Renouf: "Standard library confusion"
- Next in thread: Francis Glassborow: "Re: Standard library confusion"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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!
- Next message: Chris \( Val \): "Re: Been asked a million times but what's the best book or just use the Internet to learn C++?"
- Previous message: Chris \( Val \): "Re: When to introduce exception safety"
- In reply to: Walkaway Renouf: "Standard library confusion"
- Next in thread: Francis Glassborow: "Re: Standard library confusion"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|