[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Problem with 'import' directive
From: |
Pascal Bourguignon |
Subject: |
Re: Problem with 'import' directive |
Date: |
Wed, 5 Feb 2003 20:59:24 +0100 |
Nicola Pero writes:
> If you think it's a compiler bug (it looks like) please submit the bug to
> the GCC bug tracking system at
>
> http://gcc.gnu.org/cgi-bin/gnatsweb.pl
>
> [It might not get fixed soon, but at least it's recorded, and someone
> will hopefully fix at some point.]
>
> > I have problem with #import directive on my Linux Red Hat 7.2 machine (gstep
> > 0.8.0, gcc3)
> >
> > My application has the following structure
> >
> > A.subproj contains files: A1, A2, ...
> > B.subproj contains files: B1, B2, ...
> >
> > A1 file has import:
> > ...
> > #import "A2"
> > ...
> >
> > A2 file has import:
> > ...
> > #import "../B.subproj/B1"
> > ...
> >
> > B1 file has import:
> > ...
> > #import "../A.subproj/A2"
> > ...
> >
> > Compilation of this project terminate with error:
> > ... duplicated declaration of ... (list of some symbols from A2 file)
> >
> > I think, that compilator consider importing of files: "A2" and
> > "../A.subproj/A2" as two different files.
> > (On Solaris 8, or Openstep for Mach systems this problem does not appear)
> >
> > Is there some solution for this problem ?
>
> As a last resort ... using #include and include guards ? ;-)
Indeed, that's a typical case where #import does not work and why it's
discouraged/deprecated. Use #include.
On the other hand, either with #include if you insist to use #import,
I've found much less problems when writing only the file name in the
#include or #import directive and dealing with paths only on the
compiler command line argument with lists of -I.
In the makefiles of the B.subproj, I would have:
INCLUDES=-I. -I../A.subproj
while in the makefiles of the A.subproj, I would have:
INCLUDES-I. -I../B.subproj
The -I. being before the other -I options because if there are files
with the same name in several packages, the local one must take
precedence. By the same token, if a package C is a subpackage of the
package B, then it should appear before in the INCLUDES list.
--
__Pascal_Bourguignon__ http://www.informatimago.com/
----------------------------------------------------------------------
There is a fault in reality. Do not adjust your minds. -- Salman Rushdie