Thread overview
Reference to an unresolved external symbol
Sep 07, 2022
Injeckt
Sep 07, 2022
rikki cattermole
Sep 07, 2022
Injeckt
Sep 07, 2022
rikki cattermole
Sep 07, 2022
Injeckt
Sep 07, 2022
Dennis
Sep 07, 2022
Injeckt
September 07, 2022

Hi guys, I have an issue when I compile program with using windows api, I got this message:
"reference to an unresolved external symbol _MessageBoxW@16". I just created simple hello world using winapi and MessageBox.

import core.runtime;
import std.stdio;
import std.string;
import core.sys.windows.windows;

extern(Windows)
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int nCmdShow) {
    int result;

    try {
        Runtime.initialize();
        result = myWinMain(hInstance, hPrevInstance, cmdLine, nCmdShow);
        Runtime.terminate();
    } catch (Throwable e) {
        result = 0;
    }

    return result;
}

int myWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR cmdLine, int nCmdShow) {
    MessageBox(null, "Hello", "D!", MB_OK);

    return 0;
}
September 07, 2022
You have probably forgotten to link against user32.
September 07, 2022
On Wednesday, 7 September 2022 at 10:01:11 UTC, rikki cattermole wrote:
>
> You have probably forgotten to link against user32.

I guess you right. But I don't know how i gonna link libs when I'm using "dmd main.d". Tell me please.
September 07, 2022
On 07/09/2022 10:14 PM, Injeckt wrote:
> On Wednesday, 7 September 2022 at 10:01:11 UTC, rikki cattermole wrote:
>>
>> You have probably forgotten to link against user32.
> 
> I guess you right. But I don't know how i gonna link libs when I'm using "dmd main.d". Tell me please.

I think it is as simple as adding user32.lib to dmd (directly).
September 07, 2022
On Wednesday, 7 September 2022 at 10:31:02 UTC, rikki cattermole wrote:
>
> On 07/09/2022 10:14 PM, Injeckt wrote:
>> On Wednesday, 7 September 2022 at 10:01:11 UTC, rikki cattermole wrote:
>>>
>>> You have probably forgotten to link against user32.
>> 
>> I guess you right. But I don't know how i gonna link libs when I'm using "dmd main.d". Tell me please.
>
> I think it is as simple as adding user32.lib to dmd (directly).

LOL! WTF?!? It works! Thanks Sensei.
September 07, 2022

On Wednesday, 7 September 2022 at 10:14:22 UTC, Injeckt wrote:

>

I guess you right. But I don't know how i gonna link libs when I'm using "dmd main.d".

Another way is to add this to your code:

pragma(lib, "User32");
September 07, 2022

On Wednesday, 7 September 2022 at 10:50:17 UTC, Dennis wrote:

>

On Wednesday, 7 September 2022 at 10:14:22 UTC, Injeckt wrote:

>

I guess you right. But I don't know how i gonna link libs when I'm using "dmd main.d".

Another way is to add this to your code:

pragma(lib, "User32");

Oh thank you. I didn't knew that, I thought that it only works in visual studio.
Comrades, I need to use inet_ntop() from Ws2tcpip.h, but how I gonna include this header file to my code file?