Thread overview
Import static library by DUB (linking)
May 01
Wusiki
May 02
Wusiki
May 01

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?

May 02

On Saturday, 1 May 2021 at 18:30:26 UTC, Wusiki wrote:

>

Lib:

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

FYI, static has no meaning at module scope.

>

(Can't find -ltestlib)

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

Did you compile testlib.d into a library? I only ask because you didn't show a command line for it.

May 02

On Sunday, 2 May 2021 at 04:42:42 UTC, Mike Parker wrote:

>

On Saturday, 1 May 2021 at 18:30:26 UTC, Wusiki wrote:

FYI, static has no meaning at module scope.

Ok, I replaced abc to abc() string function;

>

Did you compile testlib.d into a library? I only ask because you didn't show a command line for it.

Yes.
My tree:

  • Root
    • libs
      • testlib.a
    • source
      • app.d
    • dub.json

testlib.a was build also with DUB where targetType was "library";