"module is in multiple packages" error
Chris Nicholson-Sauls
ibisbasenji at gmail.com
Wed Jan 3 19:45:17 PST 2007
Jona Joachim wrote:
> On Thu, 04 Jan 2007 01:17:33 +0100, Johan Granberg wrote:
>
>> Jona Joachim wrote:
>>
>>> Hi!
>>> I have to bother you with a beginner problem...
>>> I want to develop a spring model engine where you have pointmasses
>>> attached to spring which oscillate and stuff.
>>> I created a module called "connectors" which contains all sorts of
>>> connectors like springs, dampers, ... and a module called "point" which
>>> contains pointmasses and hooks.
>>> Now a connector should know what pointmasses are attached to it and a
>>> pointmass should know to which connectors it is attached...
>>> That's why point.d does a "private import connector" and connector.d does
>>> a "private import point". This works very well in C with header files and
>>> #ifdefs. However gdc throws following error:
>>>
>>> gdc -I/home/jona/prog/d/derelict -O2 -fno-strict-aliasing -c point.d
>>> connector.d:5: module constructor.point is in multiple packages
>>> constructor.point gmake: *** [point.o] Error 1
>>>
>>> Could anybody tell me how I should manage this kind of situation?
>>>
>>> Thanks a lot,
>>> Jona
>> Try declaring the modules explicityl.
>>
>> in point.d you write:
>> module point;//or directoryname.subdirectoryname.point
>>
>> and in constructor you write:
>> module constructor;
>>
>> if this doesent work how does you directory structur looks like (is point
>> and constructor in the same directory?)
>
> "constructor" is the (temporary) name of the project. All files are in the
> same directory. I declared all modules explicitly like this:
> module constructor.point;
> or
> module constructor.connector;
> and so on.
>
> I just found out that my problem disappears when I omit the
> "constructor." part.
> I don't understand why it all went fine using the above naming scheme
> until two modules tried to import themselves mutually and then in that
> case it didn't work anymore.
> However I'm happy that it seems to work now!
>
> Thanks for your help!
>
> Jona
Aha! There's your problem, then. :) You were declaring your modules as
"constructor.point" and then attempting to import them as "point". Therefore the compiler
was seeing a package mismatch between package "constructor" and package-blank (or the
no-package, or whatever you want to call it). Imports use the fully qualified name of the
module, but this name is technically determined by the initial "module X;" statement of
the target module. Modules within the same package /still/ use the fully qualified name
to specify imports.
For example, a selection of the file structure of my own Bovis project:
# bovis/
# Main
# Types
# db/
# Database
# Object
In order for bovis.Main to import the Database module, I issue:
import bovis .db .Database ;
In order for bovis.db.Database to import the Object module, I issue:
import bovis .db .Object ;
In order for bovis.db.Object to import the Types module, I issue:
import bovis .Types ;
All the same. Hopefully you understand what I'm trying to get across. :)
-- Chris Nicholson-Sauls
More information about the Digitalmars-d-learn
mailing list