Thread overview
how to link self made lib using dub
Jul 06, 2018
Flaze07
Jul 06, 2018
Timoses
Jul 07, 2018
Flaze07
July 06, 2018
I have been trying to link self made .lib, and have tried to use it several times, I failed..
so, here I have a file in this path : Z:\programming\D\usefulFiles\experiment\source\output.d

it has

module output;

class Output {
public:
    static void write( string msg ) {
        import std.stdio;
        writeln( msg );
    }
}

and then I compiled it into library using dub project with this file in a path : Z:\programming\D\usefulFiles\experiment\dub.json

{
  "name" : "experiment",
  "targetType": "library",
  "targetPath": "lib",
  "sourcePaths": [
    "source",
  ],
}

then, I made a project, with this main in this path : Z:\programming\D\experimentLib\source\main.d

it contains this

module main;

import std.stdio;

import source.output;

void main( string[] args ) {
    Output.write( "lol" );
    readln();
}

and then, I have a dub file in this path : Z:\programming\D\experimentLib\dub.json

it contains :

{
  "name" : "experimentlib",
  "targetType": "executable",
  "targetPath": "bin",
  "importPaths": [
    "Z:\\programming\\D\\usefulFiles\\experiment\\",
  ],
  "lflags": [
    "+Z:\\programming\\D\\usefulFiles\\experiment\\lib\\",
  ],
}

so, I have made lflags to include the lib in experiment, but still, it failed to linker ( it compiles fine, but the linker fails )


July 06, 2018
On Friday, 6 July 2018 at 17:08:48 UTC, Flaze07 wrote:
> [...]
> then, I made a project, with this main in this path : Z:\programming\D\experimentLib\source\main.d
>
> it contains this
>
> module main;
>
> import std.stdio;
>
> import source.output;

Shouldn't this be 'import output'?

>
> void main( string[] args ) {
>     Output.write( "lol" );
>     readln();
> }
>
> and then, I have a dub file in this path : Z:\programming\D\experimentLib\dub.json
>
> it contains :
>
> {
>   "name" : "experimentlib",
>   "targetType": "executable",
>   "targetPath": "bin",
>   "importPaths": [
>     "Z:\\programming\\D\\usefulFiles\\experiment\\",

and this '...\\experiment\\source\\'? (I'm not accustomed to Windows..)

>   ],
>   "lflags": [
>     "+Z:\\programming\\D\\usefulFiles\\experiment\\lib\\",
>   ],
> }
>
> so, I have made lflags to include the lib in experiment, but still, it failed to linker ( it compiles fine, but the linker fails )

You could also add a dependency to your other dub project and dub should automatically add the import and linker flags.
Add this to your dub.json:

"dependencies":
{
    "experiment": {"version": "*", "path": "../experiment"}
}

I didn't test this now, but it should work something like that (again, not sure about Windows path...).

See also: http://code.dlang.org/package-format?lang=json#version-specs
July 07, 2018
On Friday, 6 July 2018 at 21:13:37 UTC, Timoses wrote:
> Shouldn't this be 'import output'?
nah, because I didn't import source directly, I import experiment so in order to use it, I do source/output.d, which when importing module means, source.output
> and this '...\\experiment\\source\\'? (I'm not accustomed to Windows..)

nope, because I want to do make some sort of a package thing
>
> You could also add a dependency to your other dub project and dub should automatically add the import and linker flags.
> Add this to your dub.json:
>
> "dependencies":
> {
>     "experiment": {"version": "*", "path": "../experiment"}
> }
>
> I didn't test this now, but it should work something like that (again, not sure about Windows path...).
>
> See also: http://code.dlang.org/package-format?lang=json#version-specs

huh, didn't know I could do that