www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - dmd linker (OPTLINK) gives Error 42: Symbol Undefined when using extern

reply Tal <publictal gmail.com> writes:
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 ?
Dec 25 2011
next sibling parent reply Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
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?
Dec 25 2011
parent reply Tal <publictal gmail.com> writes:
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 ?
Dec 25 2011
next sibling parent reply Joshua Reusch <yoschi arkandos.de> writes:
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.
Dec 25 2011
parent reply Tal <publictal gmail.com> writes:
I'm quite new to this language, could you please provide a short snippet of code
to clarify ?
Dec 25 2011
parent reply Joshua Reusch <yoschi arkandos.de> writes:
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?"; }
Dec 25 2011
parent Re: dmd linker (OPTLINK) gives Error 42: Symbol Undefined when using extern <publictal gmail.com> writes:
Thanks, this is it!
Dec 27 2011
prev sibling parent Joshua Reusch <yoschi arkandos.de> writes:
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);
Dec 25 2011
prev sibling parent "Jakob Ovrum" <jakobovrum gmail.com> writes:
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.
Dec 25 2011