www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - x64 Link Issues - Can someone please help?

reply "Trey Brisbane" <tbrisbane hotmail.com> writes:
Hey all,

I'm currently using D for a hook-based project that requires me 
to build both a 32bit and 64bit DLL. Naturally, the 32bit DLL 
builds fine, however I'm encountering linking issues for the 
64bit.
I followed the instructions at 
http://wiki.dlang.org/Installing_DMD_on_64-bit_Windows_7_(COFF-compatible) 
for setting up 64bit building (albeit I didn't use his 
environment variables - I just put the paths into sc.ini 
directly), so if there's a problem with my setup, I don't see it.

Here is my build output (I'm using Xamarin Studio with Mono-D, if 
that means anything):

---------------------------------------------------------------------------

Building: HookLib (Debug|x64)

Performing main compilation...

Current dictionary: 
C:\Development\Projects\EyefinityMaximizer\HookLib

dmd.exe -debug -gc "main.d" 
"C:\Development\Projects\EyefinityMaximizer\EyefinityMaximizer\eyemax\WinAPI.d" 
"HookLib.def" "user32.lib" 
"-IC:\Development\Compilers\D\dmd2\src\phobos" 
"-IC:\Development\Compilers\D\dmd2\src\druntime\src" 
"-L/IMPLIB:C:\Development\Projects\EyefinityMaximizer\bin\De
ug\HookLib.x64.lib" 
"-odobj\Debug" 
"-ofC:\Development\Projects\EyefinityMaximizer\bin\Debug\HookLib.x64.dll" 
-m64

HookLib.def(1) : warning LNK4017: EXETYPE statement not supported 
for the target platform; ignored

HookLib.def(2) : warning LNK4017: SUBSYSTEM statement not 
supported for the target platform; ignored

HookLib.x64.obj : warning LNK4197: export 'CallWndProc' specified 
multiple times; using first specification

    Creating library 
C:\Development\Projects\EyefinityMaximizer\bin\Debug\HookLib.x64.lib 
and object 
C:\Development\Projects\EyefinityMaximizer\bin\Debug\HookLib.x64.exp

phobos64.lib(dmain2_4ac_1a5.obj) : error LNK2019: unresolved 
external symbol _Dmain referenced in function main

C:\Development\Projects\EyefinityMaximizer\bin\Debug\HookLib.x64.dll 
: fatal error LNK1120: 1 unresolved externals

--- errorlevel 1120

Exit code 1120

Build complete -- 1 error, 0 warnings

---------------------------------------------------------------------------

As you can see, there appears to be an issue with my usage of 
WinMain() as opposed to just main(). For 32bit building, the 
documentation states that the compiler recognizes WinMain and 
works accordingly - is this also the case for 64bit building?

Here is my WinMain function, in case I'm doing something wrong 
with it:

---------------------------------------------------------------------------

extern(Windows) int WinMain(HINSTANCE hInstance, HINSTANCE 
hPrevInstance, LPSTR lpCmdLine, int iCmdShow) {
	int result;
	void exceptionHandler(Throwable e) { throw e; }

	// Init the D runtime
	try {
		Runtime.initialize(&exceptionHandler);
		result = myWinMain(hInstance, hPrevInstance, lpCmdLine, 
iCmdShow);
		Runtime.terminate(&exceptionHandler);
	} catch (Throwable e) {
		MessageBoxA(null, e.toString().toStringz, "Error", MB_OK | 
MB_ICONEXCLAMATION);
		result = 0;
	}
	
	return result;
}

---------------------------------------------------------------------------

Any assistance would be appreciated, as this project is stalled 
until I can build 64bit binaries.

Thanks and regards,
Trey
Apr 18 2013
next sibling parent "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Friday, 19 April 2013 at 00:24:27 UTC, Trey Brisbane wrote:
 As you can see, there appears to be an issue with my usage of 
 WinMain() as opposed to just main(). For 32bit building, the 
 documentation states that the compiler recognizes WinMain and 
 works accordingly - is this also the case for 64bit building?

The entry point for DLLs is the DllMain function, not WinMain. I'm not sure why building a DLL with a WinMain entry point would succeed - I'd assume the resulting DLL wouldn't work. In the future, consider posting questions on how to use D to the digitalmars.D.learn group.
Apr 18 2013
prev sibling next sibling parent "Trey Brisbane" <tbrisbane hotmail.com> writes:
On Friday, 19 April 2013 at 00:53:28 UTC, Vladimir Panteleev 
wrote:
 On Friday, 19 April 2013 at 00:24:27 UTC, Trey Brisbane wrote:
 As you can see, there appears to be an issue with my usage of 
 WinMain() as opposed to just main(). For 32bit building, the 
 documentation states that the compiler recognizes WinMain and 
 works accordingly - is this also the case for 64bit building?

The entry point for DLLs is the DllMain function, not WinMain. I'm not sure why building a DLL with a WinMain entry point would succeed - I'd assume the resulting DLL wouldn't work. In the future, consider posting questions on how to use D to the digitalmars.D.learn group.

You're completely right. It seems I copy+pasted from the wrong source file by mistake. My DLLMain (not WinMain) is as follows: ------------------------------------------------------------------- extern (Windows) BOOL DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved) { // Main DLL switch switch (ulReason) { case DLL_PROCESS_ATTACH: g_hInst = hInstance; dll_process_attach( hInstance, true ); break; case DLL_PROCESS_DETACH: dll_process_detach( hInstance, true ); break; case DLL_THREAD_ATTACH: dll_thread_attach( true, true ); break; case DLL_THREAD_DETACH: dll_thread_detach( true, true ); break; default: break; } return true; } ------------------------------------------------------------------- With regards to digitalmars.D.learn - I had considered posting there, but considering this isn't really a question about learning D, but rather about getting an existing D project to build, I decided against it. If that is however the preferred location for such a question, I will post there next time as you suggested. :)
Apr 18 2013
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Thu, 18 Apr 2013 21:19:34 -0400, Trey Brisbane <tbrisbane hotmail.com>  
wrote:

 With regards to digitalmars.D.learn - I had considered posting there,  
 but considering this isn't really a question about learning D, but  
 rather about getting an existing D project to build, I decided against  
 it. If that is however the preferred location for such a question, I  
 will post there next time as you suggested. :)

d.learn is for learning, or issues with building, or whatever. If it's something you don't know that you want to find out, it goes there. I guess a rule of thumb is "if I have a question that I'm pretty sure someone has the answer to, it should go there." This NG is for general discussion about D features, proposals, interesting articles or related D posts, pretty much everything else. Most of us look at both, so use your best judgment, if you post to the wrong place, it's not the end of the world :) -Steve
Apr 19 2013
prev sibling parent "Trey Brisbane" <tbrisbane hotmail.com> writes:
On Friday, 19 April 2013 at 13:52:54 UTC, Steven Schveighoffer 
wrote:
 On Thu, 18 Apr 2013 21:19:34 -0400, Trey Brisbane 
 <tbrisbane hotmail.com> wrote:

 With regards to digitalmars.D.learn - I had considered posting 
 there, but considering this isn't really a question about 
 learning D, but rather about getting an existing D project to 
 build, I decided against it. If that is however the preferred 
 location for such a question, I will post there next time as 
 you suggested. :)

d.learn is for learning, or issues with building, or whatever. If it's something you don't know that you want to find out, it goes there. I guess a rule of thumb is "if I have a question that I'm pretty sure someone has the answer to, it should go there." This NG is for general discussion about D features, proposals, interesting articles or related D posts, pretty much everything else. Most of us look at both, so use your best judgment, if you post to the wrong place, it's not the end of the world :) -Steve

I have made a post in digitalmars.D.learn regarding this issue. Feel free to delete this thread. :)
Apr 19 2013