Thread overview
DMD + Dynamic Library.
Mar 08, 2017
Damien Gibson
Mar 08, 2017
Jerry
Mar 08, 2017
Damien Gibson
Mar 09, 2017
evilrat
Mar 09, 2017
Damien Gibson
Mar 11, 2017
Cassio Butrico
Mar 15, 2017
Damien Gibson
Mar 15, 2017
Damien Gibson
Mar 15, 2017
Cassio Butrico
Mar 15, 2017
Damien Gibson
March 08, 2017
Hi everyone. My first post here - I'm not one to usually resort to trying to ask forums directly for help but I'm a bit desperate at this point as I have wasted about 3 days in total of no-life googling trying to figure something out here.

My current setup works fine for creation of EXE's and Static libs. Dynamic libs are the only problem. I have some libraries I created and used just fine with static libs that I'd like to start using dynamically as managing them with multiple projects has just become too cumbersome.

My setup uses Mono-D using -shared and -H(-shared should already be called as it already generated .lib and .dll files but I added again just in case) and creating a new EXE project and trying to use the functions from the generated .di files works fine -> As long as the lib was generated static. While attempting to use dynamic generated .lib I always get the error "Library Reference Missing".

On each of my source files I've attempted adding export extern(D): right after Module declaration(Which again works just fine when using static edition of .lib) as well as I've used this for the dllmain (Which has only been modified slightly from the ones in guides)

version(Windows) {
	import core.sys.windows.windows : HINSTANCE;
	extern(Windows)	bool DllMain(HINSTANCE hInstance, uint ulReason, void* reserved) {
		import core.sys.windows.dll, core.sys.windows.windows;
		switch(ulReason) {
			default: assert(0);
			case DLL_PROCESS_ATTACH: return dll_process_attach( hInstance, true );
			case DLL_PROCESS_DETACH: dll_process_detach( hInstance, true );	return true;
			case DLL_THREAD_ATTACH:	return dll_thread_attach( true, true );
			case DLL_THREAD_DETACH:	return dll_thread_detach( true, true );
		}
	}
}


I've compiled EVERYTHING into x32 for windows and this being of course with the latest dmd2 compiler.

I'm all out of ideas here. From some of the threads I've come across researching the .def files that were in the main guides aren't needed as long as using the export extern(D): however whether or not they are actually needed or not -> Either the compiler or linker were throwing errors(I cant remember which).

I've even tried running .def made for example modules as well and it gave the same error so i know i wasn't just making it improperly.

I'm literally a couple tests from pulling my hair out so any wisdom on this issue would be greatly appreciated!
March 08, 2017
You have to use "export" for any symbol to be visible from a dll. On Windows by default nothing is exported.
March 08, 2017
On Wednesday, 8 March 2017 at 06:28:47 UTC, Jerry wrote:
> You have to use "export" for any symbol to be visible from a dll. On Windows by default nothing is exported.

Would "export" and "export extern(D):" not be the same? Im confuseled..
March 09, 2017
On Wednesday, 8 March 2017 at 18:21:35 UTC, Damien Gibson wrote:
> On Wednesday, 8 March 2017 at 06:28:47 UTC, Jerry wrote:
>> You have to use "export" for any symbol to be visible from a dll. On Windows by default nothing is exported.
>
> Would "export" and "export extern(D):" not be the same? Im confuseled..

They are independent.

"export" simply tells compiler/linker to make symbol public(i.e. available for dynamic loading from lib), note that on *nix systems all symbols are public by default.

"extern" thing controls symbol name mangling and calling conventions(yes, it has no meaning for data)

March 09, 2017
Well i guess ill try turning it to export everywhere then in a bit and report back if it worked out.
March 11, 2017
On Wednesday, 8 March 2017 at 18:21:35 UTC, Damien Gibson wrote:
> On Wednesday, 8 March 2017 at 06:28:47 UTC, Jerry wrote:
>> You have to use "export" for any symbol to be visible from a dll. On Windows by default nothing is exported.
>
> Would "export" and "export extern(D):" not be the same? Im confuseled..

You have to use


	extern (C) {
	 import std.stdio;
	export{
	
	void dllprint() {
		writeln("\nmydll.dll read ok!!!\n");
	}

	int Myadd(int x, int y) {
		return x + y;
	}

}
}


March 15, 2017
Sorry for late reply, had rough irl stuff... Anyway I tried the suggestion for extern and for the export(C) extern but neither of those work. I dont have a working linux box to test against to ensure that it is a windows related problem but I appreciate the suggestions offered.
March 15, 2017
If it helps to know i also get in the other little window that tells me the activate compiler commands and stuff that the symbols for the functions i called undefined while the other side just said library reference not found.
March 15, 2017
On Wednesday, 15 March 2017 at 07:03:19 UTC, Damien Gibson wrote:
> If it helps to know i also get in the other little window that tells me the activate compiler commands and stuff that the symbols for the functions i called undefined while the other side just said library reference not found.


I have an example of how to create a dll in d, read in c and d, if you want I can post the files, it's just an example to clarify, I use windows 10 32b and dmd 2.72 - yes my english is Too bad ... sorry. I speak Brazilian Portuguese.
March 15, 2017
> I have an example of how to create a dll in d, read in c and d, if you want I can post the files, it's just an example to clarify, I use windows 10 32b and dmd 2.72 - yes my english is Too bad ... sorry. I speak Brazilian Portuguese.

I would love that :D And no dont worry your english was perfectly fine!