Internal / external libraries

Hi people, feels like an easy question but this is driving me crazy.

Given some contract structure with an external library folder including a lib.sw entry point that mods all the other libraries of the library folder. How do I use library_a inside library_b?

This was incredibly easy before the previous library changes.
So what I tried and didn’t work (inside library_b):

mod library_a; // can't find file

use library_a::*; // mod library_b::library_a could not be found

use ::library_a::*; // module library_a could not be found

Thanks for any help :slight_smile:

1 Like

Okay, found the reason (thanks Armand) and I can hardly believe that this can be intended:

use ::library_a::*;

… works BUT ONLY if library_b is declared BEFORE library_a inside the lib.sw mod file. In a bigger project, “strategically” ordering all the libraries in the mod file would be really annoying.

1 Like

Glad to hear you got this working!
This is indeed a known issue. Fortunately there is work underway in the compiler that will enable fixing this once and for all.
In the Sway stdlib, we have to deal with this in our non-trivial lib.sw file and it is most definitely annoying. :slightly_smiling_face:

Thank you Nick, much appreciated!