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

wjoe invalid at example.com
Fri Sep 18 12:28:30 UTC 2020


On Friday, 18 September 2020 at 12:03:45 UTC, Mike Parker wrote:
> On Friday, 18 September 2020 at 11:38:14 UTC, wjoe wrote:
>> Something like this:
>>
>> configuration "lib" {
>>   targetType "dynamicLibrary"
>>   sourceDir "source/lib/"
>> }
>>
>> configuration "app" {
>>   targetType "executable"
>>   sourceFiles "source/app.d"
>>   linkWith "lib"
>> }
>>
>> I found subConfiguration in the docs but that seems to be 
>> related to external dependencies.
>>
>> app.d merely provides a CLI to the library as well as an 
>> option to run as a server. I don't want to have the overhead 
>> of an entire git repo and such for something that is a single 
>> file and also closely related to the library.
>
> Yes, this is possible. Should be something like this:
>
> configuration "lib" {
>    targetType "dynamicLibrary"
>    targetPath "lib"
>    sourcePaths "source/lib/"
>    excludedSourceFiles "source/app.d"
> }
>
> configuration "app" {
>    targetType "executable"
>    mainSourceFile "source/app.d"
>    excludedSourceFiles "source/lib/*.d"
>    importPaths "source/lib"
>    libs "lib/libName"
> }

Awesome. Thanks. And Danny to you, too.

2 issues though.
- It doesn't build the library automatically, and
- 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 ?


More information about the Digitalmars-d-learn mailing list