Aarkon
Aarkon

Reputation: 488

Local dependency not found

I have a project containing two (binary) packages, front- and backend. Both are created & managed by cargo independently. In the frontend, I want to access some types declared in the backend, so I added to the frontend’s Cargo.toml:

[dependencies.myapp-backend]
path = "../myapp-backend"

This matches my folder structure and cargo-run does not complain. Yet I can not use the crate in the frontend: When I add extern crate myapp-backend (or one of the variants with or without a _ instead of -) to my frontend’s main.rs, the compiler yells at me that it can’t find the crate.

To check wether the whole dependency statement in the Cargo.toml is evaluated at all, I flipped some letters which gave me an instant compilation error (it therefore is evaluated). Also, I exchanged the importing statement with use myapp-backend, again with variations on the hyphen, directly, which results in the expected no 'myapp_backend' external crate. I even used the alternative notation for an external dependency, with no effect:

myapp-backend = {path = "../myapp-backend"}

I am pretty sure I am missing something stupid simple, but after reading Cargo’s documentation as well as Stack Overflow up and down for two days now, I dare to ask. ^^

Upvotes: 1

Views: 619

Answers (1)

chpio
chpio

Reputation: 1054

You can not use an executable (crate with a main.rs file) as a dependency. But you could move all shared things into a 3. library crate and use that as a dependency in both executables.

Upvotes: 1

Related Questions