Thread overview
Packages and module import
Mar 19, 2018
Russel Winder
Mar 19, 2018
Adam D. Ruppe
Mar 19, 2018
Russel Winder
Mar 19, 2018
Tony
Mar 20, 2018
Jacob Carlborg
Mar 21, 2018
Russel Winder
Mar 21, 2018
Jacob Carlborg
March 19, 2018
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?


-- 
Russel.
===========================================
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


March 19, 2018
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.
March 19, 2018
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.

March 19, 2018
On Mon, 2018-03-19 at 17:49 +0000, Adam D. Ruppe via Digitalmars-d- learn wrote:
> […]
> 
> Odds are, linux_dmx.d is missing the `module libdvbv5_d.linux_dmx;` line.
> 
[…]

You are right. I was certain I had correct module statements in all the modules, but I hadn't.

-- 
Russel.
===========================================
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


March 20, 2018
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
March 21, 2018
On Tue, 2018-03-20 at 22:08 +0100, Jacob Carlborg via Digitalmars-d- learn wrote:
> 
[…]
> Not sure if this will help, but are you aware that DStep can add a package to the module declaration using "--package"?

No I wasn't. And it works a treat.

-- 
Russel.
===========================================
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


March 21, 2018
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