www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Reference to an unresolved external symbol

reply Injeckt <vinsentlou9 gmail.com> writes:
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;
     }
Sep 07 2022
parent reply rikki cattermole <rikki cattermole.co.nz> writes:
You have probably forgotten to link against user32.
Sep 07 2022
parent reply Injeckt <vinsentlou9 gmail.com> writes:
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.
Sep 07 2022
next sibling parent reply rikki cattermole <rikki cattermole.co.nz> writes:
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).
Sep 07 2022
parent Injeckt <vinsentlou9 gmail.com> writes:
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.
Sep 07 2022
prev sibling parent reply Dennis <dkorpel gmail.com> writes:
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: ```D pragma(lib, "User32"); ```
Sep 07 2022
parent Injeckt <vinsentlou9 gmail.com> writes:
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: ```D 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?
Sep 07 2022