www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Packages and module import

reply Russel Winder <russel winder.org.uk> writes:
I had assumed that a directory of modules was a package. So for
example:

	A/a.d
	A/b.d

were two modules in package A. Especially given there is a module
statement at the beginning of each module:

A/a.d has  module A.a;
A/b.d has  module A.b;

Now A.b needs to access something from A.a. I had assumed that the
import should be fully qualified. So in A.b.d:

	import A.a: thing;

This all works when building the library.


ldc2 -of=3DBuild/Release/libdvbv5_d.so -shared -defaultlib=3Dphobos2-ldc Bu=
ild/Release/source/libdvbv5_d/linux_dmx.o Build/Release/source/libdvbv5_d/d=
vb_v5_std.o Build/Release/source/libdvbv5_d/dvb_frontend.o Build/Release/so=
urce/libdvbv5_d/dvb_log.o Build/Release/source/libdvbv5_d/dvb_demux.o Build=
/Release/source/libdvbv5_d/dvb_fe.o Build/Release/source/libdvbv5_d/dvb_fil=
e.o Build/Release/source/libdvbv5_d/dvb_scan.o Build/Release/source/libdvbv=
5_d/dvb_sat.o -L-ldruntime-ldc


However when trying to build the unit-tests:


ldc2 -I=3Dsource -unittest --main -of=3DBuild/Test/libdvbv5_d source/libdvb=
v5_d/linux_dmx.d source/libdvbv5_d/dvb_v5_std.d source/libdvbv5_d/dvb_front=
end.d source/libdvbv5_d/dvb_log.d source/libdvbv5_d/dvb_demux.d source/libd=
vbv5_d/dvb_fe.d source/libdvbv5_d/dvb_file.d source/libdvbv5_d/dvb_scan.d s=
ource/libdvbv5_d/dvb_sat.d
source/libdvbv5_d/dvb_demux.d(35): Error: module linux_dmx from file source=
/libdvbv5_d/linux_dmx.d must be imported with 'import linux_dmx;'


Am I just missing something simple?


--=20
Russel.
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Dr Russel Winder      t: +44 20 7585 2200
41 Buckmaster Road    m: +44 7770 465 077
London SW11 1EN, UK   w: www.russel.org.uk
Mar 19 2018
next sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Monday, 19 March 2018 at 17:29:10 UTC, Russel Winder wrote:
 Especially given there is a module statement at the beginning 
 of each module:
It is not especially, it is ONLY because of the module statement. The directory layout is a convention so tools can find the module file, but only the module declaration line in the code itself defines the authoritative name.
 source/libdvbv5_d/dvb_demux.d(35): Error: module linux_dmx from 
 file source/libdvbv5_d/linux_dmx.d must be imported with 
 'import linux_dmx;'
Odds are, linux_dmx.d is missing the `module libdvbv5_d.linux_dmx;` line. Any import statements and module statements need to use the same name. The layout in the file system is secondary to this.
Mar 19 2018
parent Russel Winder <russel winder.org.uk> writes:
On Mon, 2018-03-19 at 17:49 +0000, Adam D. Ruppe via Digitalmars-d-
learn wrote:
 [=E2=80=A6]
=20
 Odds are, linux_dmx.d is missing the `module=20
 libdvbv5_d.linux_dmx;` line.
=20
[=E2=80=A6] You are right. I was certain I had correct module statements in all the modules, but I hadn't. --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Dr Russel Winder t: +44 20 7585 2200 41 Buckmaster Road m: +44 7770 465 077 London SW11 1EN, UK w: www.russel.org.uk
Mar 19 2018
prev sibling next sibling parent Tony <tonytdominguez aol.com> writes:
On Monday, 19 March 2018 at 17:29:10 UTC, Russel Winder wrote:
 I had assumed that a directory of modules was a package. So for 
 example:

 [...]
On Monday, 19 March 2018 at 17:29:10 UTC, Russel Winder wrote: To my amateur eyes, first command-line build looks like a linking of object files into a .so. The second command-line build looks like compilation is taking place. Seems like the command-line used to compile the library is missing.
Mar 19 2018
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2018-03-19 18:29, Russel Winder wrote:
 I had assumed that a directory of modules was a package. So for
 example:

 	A/a.d
 	A/b.d

 were two modules in package A. Especially given there is a module
 statement at the beginning of each module:

 A/a.d has  module A.a;
 A/b.d has  module A.b;

 Now A.b needs to access something from A.a. I had assumed that the
 import should be fully qualified. So in A.b.d:

 	import A.a: thing;

 This all works when building the library.


 ldc2 -of=Build/Release/libdvbv5_d.so -shared -defaultlib=phobos2-ldc
Build/Release/source/libdvbv5_d/linux_dmx.o
Build/Release/source/libdvbv5_d/dvb_v5_std.o
Build/Release/source/libdvbv5_d/dvb_frontend.o
Build/Release/source/libdvbv5_d/dvb_log.o
Build/Release/source/libdvbv5_d/dvb_demux.o
Build/Release/source/libdvbv5_d/dvb_fe.o
Build/Release/source/libdvbv5_d/dvb_file.o
Build/Release/source/libdvbv5_d/dvb_scan.o
Build/Release/source/libdvbv5_d/dvb_sat.o -L-ldruntime-ldc


 However when trying to build the unit-tests:


 ldc2 -I=source -unittest --main -of=Build/Test/libdvbv5_d
source/libdvbv5_d/linux_dmx.d source/libdvbv5_d/dvb_v5_std.d
source/libdvbv5_d/dvb_frontend.d source/libdvbv5_d/dvb_log.d
source/libdvbv5_d/dvb_demux.d source/libdvbv5_d/dvb_fe.d
source/libdvbv5_d/dvb_file.d source/libdvbv5_d/dvb_scan.d
source/libdvbv5_d/dvb_sat.d
 source/libdvbv5_d/dvb_demux.d(35): Error: module linux_dmx from file
source/libdvbv5_d/linux_dmx.d must be imported with 'import linux_dmx;'


 Am I just missing something simple?
Not sure if this will help, but are you aware that DStep can add a package to the module declaration using "--package"? -- /Jacob Carlborg
Mar 20 2018
parent reply Russel Winder <russel winder.org.uk> writes:
On Tue, 2018-03-20 at 22:08 +0100, Jacob Carlborg via Digitalmars-d-
learn wrote:
=20
[=E2=80=A6]
 Not sure if this will help, but are you aware that DStep can add a=20
 package to the module declaration using "--package"?
No I wasn't. And it works a treat. --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Dr Russel Winder t: +44 20 7585 2200 41 Buckmaster Road m: +44 7770 465 077 London SW11 1EN, UK w: www.russel.org.uk
Mar 21 2018
parent Jacob Carlborg <doob me.com> writes:
On 2018-03-21 17:06, Russel Winder wrote:

 No I wasn't. And it works a treat.
Cool :). I recommend having a look at the changelog and the usage information (--help). -- /Jacob Carlborg
Mar 21 2018