I am having trouble with D's package.d
feature. I have my package.d
file:
module dew;
public
import dew.util;
I then have util.d
:
module dew.util;
struct Size
{
int width;
int height;
}
When I try to use it in another project, it gives me this error: I know that this should work, because projects on GitHub use it, specifically bindbc-sdl.
Your code is correct. By the error message I'm assuming your project layout with DUB probably looks something like this:
However this would be incorrect. By default DUB only uses import folders instead of specifying all input source files, so the compiler attempts to discover the files from the import paths in the filesystem. The compiler dumped the import paths it searches in in your error screenshot.
The rough compiler equivalent to what it's doing right now is (see
dub -v
)You need to imagine that the path whatever is written in there is invisible to the compiler, so the dew/source/ path is just some opaque string the compiler doesn't interpret. Now all that the compiler sees is a package.d and util.d in its search paths. However for imports from folders to function, they need to correspond to the filesystem layout, i.e. you need to have a folder named
dew
where your files are stored in.So a module named
dew.util
would correspond todew/util.d
And your package
dew
would correspond todew/package.d
So for your dub project that means essentially that you need to move all your source files into
Alternatively it would be possible to manually specify all files one-by-one where the compiler can look them up because of the
module
declarations at the top of the file, however you lose the convenience of module names being mapped to filesystem paths, which might be something other community-made D source tools and IDEs are expecting. On the command line that would be equivalent to