Re: #include, loading, and c++
Re: #include, loading, and c++
- Subject: Re: #include, loading, and c++
- From: Jeff DuMonthier <email@hidden>
- Date: Fri, 31 Mar 2006 11:27:15 -0500
I'm going to guess that you have the randomChar.cpp file checked in
your active target. When you add files to XCode, source files (e.g.
'.cpp') files will be compiled as independent units if the boxes in the
file window are checked. Header files (e.g. '.h' and '.hpp') will not
be compiled as independent units. Including randomChar.cpp in main as
you have should work, even though it's a little nonstandard, but if the
compiler is trying to also compile randomChar.cpp as a separate unit
you will have two errors: the necessary includes will not happen for
the compilation of randomChar.cpp to succeed on its own, and your
function will be be duplicated.
You could highlight the randomChar.cpp file and uncheck the box in the
file window for inclusion in the current target, but really if you are
going to use it only for inclusion in another file and never for
separate compilation, it would be better to change the extension to
'.h' or '.hpp' to better indicate the purpose of the file and avoid the
confusion in the first place.
If you want randomChar.cpp compiled as a separate unit, you will have
to include the necessary headers in that file and make a header for it
to include in main.cpp which declares your random function. That's
normally the way you would do this as it would avoid linker errors from
duplicate definitions which would occur if you included randomChar.cpp
as is in multiple compilation units.
On Mar 31, 2006, at 10:38 AM, <email@hidden> wrote:
Hi,
According to the xcode help
2.2 Include Operation
The #include directive works by directing the C preprocessor to scan
the specified file as input before continuing with the rest of the
current file. The output from the preprocessor contains the output
already generated, followed by the output resulting from the included
file, followed by the output that comes from the text after the
#include directive. For example, if you have a header file header.h as
follows,
The problem is when I put it to use:
The following works:
************ main ***********
#include <cstdlib>
#include <fstream>
#include <iostream>
using namespace std;
but if I remove the random function and place it in a separate file as
so, it does not
***************** randomChar.cpp *************
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden