Linker Errors when Constructing an Immutable Struct
Adam Wilson via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jun 2 00:13:32 PDT 2014
Please consider the following code:
module aurora.immediate.input;
public enum Key : int { //... }
public immutable struct KeyData
{
private Key _key;
@property public Key KeyCode() { return _key; }
private bool _isDown;
@property public bool IsDown() { return _isDown; }
private bool _isUp;
@property public bool IsUp() { return _isUp; }
private bool _isRepeating;
@property public bool IsRepeating() { return _isRepeating; }
@disable this();
public immutable this(Key key, bool isDown, bool isUp, bool isRepeating =
false) nothrow
{
_key = key;
_isDown = isDown;
_isUp = isUp;
_isRepeating = isRepeating;
}
}
module aurora.immediate.window;
import aurora.immediate.input;
public class Window {
protected void delegate(immutable(KeyData) args) nothrow onKeyDown;
private LRESULT internalWndProc(HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam) nothrow {
if (onKeyDown !is null) onKeyDown(immutable KeyData(cast(Key)wParam,
true, false, false));
return 0;
}
}
When compiled and imported as a static library it fails to compile with
the following linker errors:
libaurora_immediate64d.lib(window_47a_278.obj) : error LNK2019: unresolved
external symbol _D6aurora9immediate5input7KeyData6__initZ referenced in
function _D6aurora9immediate6window6Window15internalWndProcMFNbPvkmlZl
libaurora_immediate64d.lib(window_47a_278.obj) : error LNK2019: unresolved
external symbol
_D6aurora9immediate5input7KeyData6__ctorMyFNbNcE6aurora9immediate5input3KeybbbZyS6aurora9immediate5input7KeyData
referenced in function
_D6aurora9immediate6window6Window15internalWndProcMFNbPvkmlZl
It appears that the linker cannot find .init and the .ctor. Is this a
compiler bug or am I doing something wrong? I am wondering if this is a
problem with immutable structs? Any pointers would be very appreciated.
--
Adam Wilson
GitHub/IRC: LightBender
Aurora Project Coordinator
More information about the Digitalmars-d
mailing list