Using .lib and .dll in D applications

moe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 19 08:35:04 PDT 2016


Hello,

I am new to d and doing some small test apps at the moment to 
learn d. Currently I must be missing something basic here. I have 
installed dub as a project manager and I am trying to use a .lib 
file in an app. However, I can not use a module from the .lib 
file. I get the following error:

"module barlib is in file 'barlib.d' which cannot be read"

here is what I currently have:

the file to build the library
-----------------------------
module barlib;
import std.stdio;

class BarLib
{
this(){}
	void Talk(string msg)
	{
		writeln("BL: %s", msg);
	}
}

the dub.json to build the lib
-----------------------------
{
	"name": "dbar",
	"authors": ["moe"],
	"description": "A minimal D application.",
	"copyright": "Copyright © 2016, root",
	"license": "proprietary",
	"platforms": ["windows"],
	"versions": ["DesktopApp"],
	"targetType": "staticLibrary",
	"configurations": [
	{
		"name": "debug",
		"targetPath": "bin/debug",
		"buildOptions": ["debugMode", "debugInfo"]
	},
	{
		"name": "release",
		"targetPath": "bin/release",
		"buildOptions": ["releaseMode", "optimize", "inline"]
	}
	]
}


the file for the app
--------------------
import barlib;
import std.stdio;

void main()
{
	auto b = new BarLib();
	b.Talk("Hello from barlib");
}

the dub.json for the app
------------------------
{
	"name": "dfoo",
	"authors": ["moe"],
	"description": "A minimal D application.",
	"copyright": "Copyright © 2016, root",
	"license": "proprietary",
	"platforms": ["windows"],
	"versions": ["DesktopApp"],
	"targetType": "executable",
	"configurations": [
	{
		"name": "debug",
		"targetPath": "bin/debug",
		"buildOptions": ["debugMode", "debugInfo"]
	},
	{
		"name": "release",
		"targetPath": "bin/release",
		"buildOptions": ["releaseMode", "optimize", "inline"]
	}
	]
}

I can successfully build the barlib.lib file but I can not use it 
in the app. I thought that it should be possible to simply import 
the module from the lib-file, but the app cannot find the module. 
I would like to be able to build .lib and .dll files and use them 
in other applications. Can someone tell me what I am missing?


More information about the Digitalmars-d-learn mailing list