Using D libraries with SDL. Error: "Cannot find module protobuf'

IchorDev zxinsworld at gmail.com
Sat Aug 24 12:11:03 UTC 2024


On Saturday, 24 August 2024 at 11:34:18 UTC, Nicol Farran Terra 
wrote:
>> You are importing `google.protobuf`, right?
>> Providing the app.d would be helpful, or at least a snippet of 
>> it with the import that’s giving you the ‘error’—presumably a 
>> compiler error?
>>
> No, I am just importing 'protobuf'.

Well, the package path is `google.protobuf`. If you import 
`protobuf` then you are telling the compiler to import something 
that does not exist, so naturally that gives you this error:

> If you try to import protobuf in the app.d, it just wont work. 
> Here is that error.
> source/app.d(2,8): Error: unable to read module `protobuf`
> source/app.d(2,8):        Expected 'protobuf.d' or 
> 'protobuf/package.d' in one of the following import paths:
> import path[0] = source/
> import path[1] = 
> ../../../../.dub/packages/protobuf/0.6.2/protobuf/src/
> import path[2] = /usr/include/dlang/dmd
> Error /usr/bin/dmd failed with exit code 1.

> Also, I tried with both google.protobuf and just protobuf. Same 
> error.

So, how does this error look when you `import google.protobuf`?

dub is telling you the file path:
`../../../../.dub/packages/protobuf/0.6.2/protobuf/src/` ~ 
(`protobuf.d` or `protobuf/package.d`).
If you look, you will see that there’s no such file or folder, 
but [there should be a google folder & a protobuf folder inside 
it](https://github.com/dcarp/protobuf-d/blob/master/src/google/protobuf/package.d). The folder structure defines how the modules & packages are named (i.e. `google/protobuf/package.d` => `import google.protobuf`), so in the future you can check the folder structure if you have this issue anywhere else, since sometimes dub packages just don’t say how they should be imported.

> Also the app is literally the base app when you run dub.init.
> Here is a more exact error.
> app.d(2): Error: unable to read module `protobuf`
> app.d(2):        Expected 'google/protobuf.d' or 
> 'google/protobuf/package.d' in one of the following import 
> paths:
> import path[0] = /usr/include/dlang/dmd

Are you just running dmd on `app.d` from inside `source` this 
time? If not then why are all of your project’s import paths 
missing??

> Although I do remember I got something interesting when trying 
> to build a subproject of this one (it wasnt there for some 
> reason)

Did you try `dub build protobuf:protoc-gen-d`?

> Uhh, just 'root'. Where my dub.sdl is?

Yes, that’s the root directory of your dub package.


More information about the Digitalmars-d-learn mailing list