Import static library by DUB (linking)

Wusiki wusikijeronii at gmail.com
Sat May 1 18:30:26 UTC 2021


Lib:

```
module testlib;
static string abc = "Hello World!";
```

Source file:
```
module app;
import std.stdio;
import testlib;

void main()
{
     writeln(abc);
}
```

Dub:
```
{
	"authors": [
		"WJ"
	],
	"copyright": "Copyright © 2020, ME",
	"description": "The lib test",
	"license": "proprietary",
	"name": "app",
	"targetPath": "./bin/",
	"targetType": "executable",
	"importPaths": ["libs"],
	
	"lflags":["-L/home/aleksej/Programming/Tests/ldclibtest/libs"]
}
```

I get the error:
```
app ~master: building configuration "application"...
/usr/bin/dmd -c 
-of.dub/build/application-debug-linux.posix-x86_64-dmd_v2.096.0-95A89AF60F91654EFC94DCE63378DCD4/app.o -debug -g -w -version=Have_app -Ilibs source/app.d -vcolumns
Linking...
/usr/bin/dmd 
-of.dub/build/application-debug-linux.posix-x86_64-dmd_v2.096.0-95A89AF60F91654EFC94DCE63378DCD4/app .dub/build/application-debug-linux.posix-x86_64-dmd_v2.096.0-95A89AF60F91654EFC94DCE63378DCD4/app.o -L--no-as-needed -L-L/home/aleksej/Programming/Tests/ldclibtest/libs -g
/usr/bin/ld: 
.dub/build/application-debug-linux.posix-x86_64-dmd_v2.096.0-95A89AF60F91654EFC94DCE63378DCD4/app.o: в функции «_Dmain»:
/home/aleksej/Programming/Tests/ldclibtest/source/app.d:7: 
неопределённая ссылка на «_D7testlib3abcAya»
collect2: ошибка: выполнение ld завершилось с кодом возврата 1
Error: linker exited with status 1
FAIL 
.dub/build/application-debug-linux.posix-x86_64-dmd_v2.096.0-95A89AF60F91654EFC94DCE63378DCD4/ app executable
/usr/bin/dmd failed with exit code 1.
```
(Undefined link to testlib)

I also try to add:
```
"libs": ["testlib"]
```

But then i get:
```
89AF60F91654EFC94DCE63378DCD4/app 
.dub/build/application-debug-linux.posix-x86_64-dmd_v2.096.0-95A89AF60F91654EFC94DCE63378DCD4/app.o -L--no-as-needed -L-L/home/aleksej/Programming/Tests/ldclibtest/libs -L-ltestlib -g
/usr/bin/ld: невозможно найти -ltestlib
```

(Can't find -ltestlib)

What am I do wrong? How can I link my library with my app?


More information about the Digitalmars-d-learn mailing list