Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
December 25, 2011 dmd linker (OPTLINK) gives Error 42: Symbol Undefined when using extern | ||||
---|---|---|---|---|
| ||||
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 Re: dmd linker (OPTLINK) gives Error 42: Symbol Undefined when using extern | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tal | 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 Re: dmd linker (OPTLINK) gives Error 42: Symbol Undefined when using extern | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | 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 Re: dmd linker (OPTLINK) gives Error 42: Symbol Undefined when using extern | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tal | 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 Re: dmd linker (OPTLINK) gives Error 42: Symbol Undefined when using extern | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joshua Reusch | I'm quite new to this language, could you please provide a short snippet of code to clarify ? |
December 25, 2011 Re: dmd linker (OPTLINK) gives Error 42: Symbol Undefined when using extern | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tal | 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 Re: dmd linker (OPTLINK) gives Error 42: Symbol Undefined when using extern | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tal | 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 Re: dmd linker (OPTLINK) gives Error 42: Symbol Undefined when using extern | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joshua Reusch | 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 Re: dmd linker (OPTLINK) gives Error 42: Symbol Undefined when using extern | ||||
---|---|---|---|---|
| ||||
Posted in reply to Joshua Reusch | Thanks, this is it! |
Copyright © 1999-2021 by the D Language Foundation