February 20, 2006
I have a X68Sound.dll (not mine) that I'd like to use in my project, but I can't get it to link, and being a beginner D programmer doesn't help me much. I know I've used implib as "implib /system x68sound.lib x68sound.def" to create a library and tried to link it as it follows. The .lib, .def, and .dll and all in the same directory as the rest of the code.

This is DDA.d
******************
module dda;

import std.stdio;
import X68Sound;

int main()
{
int ret;

ret = X68Sound_Start();
X68Sound_Free();

return 0;
}
******************

And this one is x68sound.d
******************
module X68Sound;

export int X68Sound_Start(int samprate=44100, int opmflag=1, int adpcmflag=1,
int betw=5, int pcmbuf=5, int late=200, double rev=1.0);
export void X68Sound_Free();
******************

And this guys is X68Sound.def
******************
LIBRARY    "X68Sound.dll"
DESCRIPTION "X68k Sound Generator"
EXPORTS
X68Sound_Start		@1
X68Sound_Samprate	@2
X68Sound_Reset		@3
X68Sound_Free		@4
X68Sound_BetwInt	@5

X68Sound_StartPcm	@6
X68Sound_GetPcm		@7

X68Sound_OpmPeek	@8
X68Sound_OpmReg		@9
X68Sound_OpmPoke	@10
X68Sound_OpmInt		@11
X68Sound_OpmWait	@12
X68Sound_OpmClock	@13

X68Sound_AdpcmPeek	@14
X68Sound_AdpcmPoke	@15
X68Sound_PpiPeek	@16
X68Sound_PpiPoke	@17
X68Sound_PpiCtrl	@18
X68Sound_DmaPeek	@19
X68Sound_DmaPoke	@20
X68Sound_DmaInt		@21
X68Sound_DmaErrInt	@22
X68Sound_MemReadFunc	@23

X68Sound_WaveFunc	@24

X68Sound_Pcm8_Out	@25
X68Sound_Pcm8_Aot	@26
X68Sound_Pcm8_Lot	@27
X68Sound_Pcm8_SetMode	@28
X68Sound_Pcm8_GetRest	@29
X68Sound_Pcm8_GetMode	@30
X68Sound_Pcm8_Abort	@31

X68Sound_TotalVolume	@32


X68Sound_ErrorCode	@33
X68Sound_DebugValue	@34
******************

And finally this is what I get...
******************
C:\Proj\DDS>dmd dda.d x68sound.lib
C:\dm\bin\link.exe dda,,,x68sound.lib+user32+kernel32/noi;
OPTLINK (R) for Win32  Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved

C:\DMD\BIN\..\lib\phobos.lib(dmain2)
Error 42: Symbol Undefined _D8X68Sound14X68Sound_StartFiiiiiidZi
C:\DMD\BIN\..\lib\phobos.lib(dmain2)
Error 42: Symbol Undefined _D8X68Sound13X68Sound_FreeFZv
******************

Please enlight me in this.
Thanks in advance,
Essoje


February 21, 2006
"Essoje Oliveira de Almeida" <Essoje_member@pathlink.com> wrote in message news:dtdfh1$2qs7$1@digitaldaemon.com...
> And finally this is what I get...
> ******************
> C:\Proj\DDS>dmd dda.d x68sound.lib
> C:\dm\bin\link.exe dda,,,x68sound.lib+user32+kernel32/noi;
> OPTLINK (R) for Win32  Release 7.50B1
> Copyright (C) Digital Mars 1989 - 2001  All Rights Reserved
>
> C:\DMD\BIN\..\lib\phobos.lib(dmain2)
> Error 42: Symbol Undefined _D8X68Sound14X68Sound_StartFiiiiiidZi
> C:\DMD\BIN\..\lib\phobos.lib(dmain2)
> Error 42: Symbol Undefined _D8X68Sound13X68Sound_FreeFZv

Those funny-looking name manglings are D name mangling.  This is because the default extern type for functions is extern(D), so DMD mangles those exported functions with D mangling.  Try surrounding the contents of the X86Sound.d module with an extern(C) block.

Though I'm not entirely sure that will work, as DMD likes to prefix an underscore when mangling names to C, and it doesn't look like there are any underscores in the def.  Go ahead and try it anyway.  It doesn't look like you're using the def file on the commandline, so OPTLINK might like the C names in the lib.