dub: Is it possible to have a library target and depend on it in the same dub config?

Mike Parker aldacron at gmail.com
Fri Sep 18 14:01:55 UTC 2020

On Friday, 18 September 2020 at 12:28:30 UTC, wjoe wrote:

> 2 issues though.
> - It doesn't build the library automatically, and

You'll have to invoke dub once for each config. Just slap both 
commands in a script.

> - Linking fails because error: ld: cannot find -llib<name>
> Built it manually via dub --config=lib and it lives inside the 
> lib directory.
> Then added lflags "-Llib" to the "app" configuration but that 
> didn't help. ld still can't find the file.
> Then I passed the absolute path and ld still complains.
> Any ideas as to why ?

It's just a matter of getting the configuration right and making 
the linker happy. I don't think I've ever linked with anything 
other than system libraries on Linux, so I really don't know what 
it expects when linking with a custom shared library outside of 
the system path.

Make sure that your library foo.so is named `libfoo.so`, when you 
pass the lib path along in dflags via -L, then make sure to 
change `libs "lib/foo"` to `libs "foo"`.

The initial failure may be because of the path in the library 
name. I remember reading somewhere long ago that if you're 
passing a path in the library name (instead of using the -L 
flag), then you have to specify the full file name, e.g. 
lib/libfoo.so. I don't know if dub will pass that along correctly 

Whatever the case, trying adding -v to your dub command line so 
you can see exactly what's dub is calling the compiler with. That 
may give you a hint.

More information about the Digitalmars-d-learn mailing list