Thread overview
dmd linker (OPTLINK) gives Error 42: Symbol Undefined when using extern
Dec 25, 2011
Tal
Dec 25, 2011
Andrej Mitrovic
Dec 25, 2011
Tal
Dec 25, 2011
Joshua Reusch
Dec 25, 2011
Tal
Dec 25, 2011
Joshua Reusch
Dec 26, 2011
Jakob Ovrum
Dec 25, 2011
Joshua Reusch
December 25, 2011
Linking the following two files gives me a link-error:

a.d:
	import std.stdio;

	extern (D) string test ();

	void main()
	{
		writeln(test());
		readln();
	}
____________________________________
b.d:
	string test () {
		return "hello";
	}
____________________________________
the error I get is:

Error 42: Symbol Undefined _D1a4testFZAya`

---errorlevel 1

What is wrong ?
December 25, 2011
You can't prototype D functions like that, they belong to a module. test is built as _D1b4testFZAya, not _D1a4testFZAya (notice the module names, a and b after _D1).

What exactly are you trying to do? DLLs?
December 25, 2011
I want to save the hInstance of WinMain so I would be able to use it later in some other module. So how do I accomplish that ?
December 25, 2011
Am 25.12.2011 22:37, schrieb Tal:
> I want to save the hInstance of WinMain so I would be able to use it later in some
> other module. So how do I accomplish that ?

just define a public variable in the global scope.
December 25, 2011
I'm quite new to this language, could you please provide a short snippet of code to clarify ?
December 25, 2011
Am 25.12.2011 23:26, schrieb Tal:
> I'm quite new to this language, could you please provide a short snippet of code
> to clarify ?

--- a.d:

import std.stdio;
import b;

void main() {
  writeln("some_var from Module b: \"", b.some_var, "\"");
}

--- b.d:

public string some_var = "Hello, world!";

//you can also use static module constructors to set your vars
static this() {
  some_var ~= " -- How are you?";
}
December 25, 2011
Am 25.12.2011 22:37, schrieb Tal:
> I want to save the hInstance of WinMain so I would be able to use it later in some
> other module. So how do I accomplish that ?

If you don't know: You can also get the HINSTANCE with GetModuleHandle(NULL);
December 26, 2011
On Sunday, 25 December 2011 at 22:46:33 UTC, Joshua Reusch wrote:
> public string some_var = "Hello, world!";

It's important to note that public is the default access level here.
December 27, 2011
Thanks, this is it!