Im attempting to build a dll which a windows program running under wine can dynamically load. The dll will be a wrapper around a linux library. In preparation ive tried to follow the instructions here http://www.winehq.org/docs/winelib-guide/bindlls with a simple example but have not succeeded. Below is the contents of the files in my directory and the commands i executed. Can anyone help out? Thanks!
MyLinuxFunc.c int MyLinuxFunc(int a,int b) { return a+b; } ----------------------------- MyLinuxFunc.h int MyLinuxFunc(int,int); ----------------------------- libMyLinuxFunc.so ----------------------------- MyWin.dll.spec 2 stdcall MyWinFunc (long long) MyProxyWinFunc ----------------------------- MyWin.c
#include <MyLinuxFunc.h> #include <windef.h> int WINAPI MyProxyWinFunc (int a,int b) { return MyLinuxFunc(a,b); } -----------------------------
winemaker . --nosource-fix --dll --single-target MyWin --nomfc -I"." -L"." -iMyLinuxFunc
make winegcc -o MyWin.so MyLinuxFunc.o MyWin.o -L. -lMyLinuxFunc MyWin.o: In function `MyProxyWinFunc': MyWin.c:(.text+0x20): undefined reference to `MyLinuxFunc' /usr/lib/wine/libwinecrt0.a(exe_main.o): In function `main': (.text+0xa0): undefined reference to `WinMain' collect2: ld returned 1 exit status winegcc: i486-linux-gnu-gcc failed make: *** [MyWin.so] Error 2
Seth,
Take a look at the source code to the CUDA 3.0 wrapper I just finished. You have some mistakes in your coding and this should help provide you a better example. When I first was coding the CUDA 2.0 wrapper some people told me to look at opengl and how it was wrapper to the linux library so that is how I came up with this.
http://shelnutt2.host56.com/wrapper.tar.gz
Generally the specfile goes like
@ stdcall cudaGetDeviceProperties( ptr long ) wine_cudaGetDeviceProperties
Then in your .c file:
cudaError_t WINAPI wine_cudaGetDeviceProperties( struct cudaDeviceProp *prop, int device) { WINE_TRACE("\n"); return cudaGetDeviceProperties(prop, device); }
Also your linking looks off. You shouldn't be linking -l"." . You need to specify the exact file, like for CUDA we did -lcudart or -lcufft.
I hope that help you some.
-Seth Shelnutt
On Wed, Jun 16, 2010 at 2:04 AM, Seth Burleigh seth@tewebs.com wrote:
Im attempting to build a dll which a windows program running under wine can dynamically load. The dll will be a wrapper around a linux library. In preparation ive tried to follow the instructions here http://www.winehq.org/docs/winelib-guide/bindlls with a simple example but have not succeeded. Below is the contents of the files in my directory and the commands i executed. Can anyone help out? Thanks!
MyLinuxFunc.c int MyLinuxFunc(int a,int b) { return a+b; }
MyLinuxFunc.h int MyLinuxFunc(int,int);
libMyLinuxFunc.so
MyWin.dll.spec 2 stdcall MyWinFunc (long long) MyProxyWinFunc
MyWin.c
#include <MyLinuxFunc.h> #include <windef.h> int WINAPI MyProxyWinFunc (int a,int b) { return MyLinuxFunc(a,b); }
winemaker . --nosource-fix --dll --single-target MyWin --nomfc -I"." -L"." -iMyLinuxFunc
make winegcc -o MyWin.so MyLinuxFunc.o MyWin.o -L. -lMyLinuxFunc MyWin.o: In function `MyProxyWinFunc': MyWin.c:(.text+0x20): undefined reference to `MyLinuxFunc' /usr/lib/wine/libwinecrt0.a(exe_main.o): In function `main': (.text+0xa0): undefined reference to `WinMain' collect2: ld returned 1 exit status winegcc: i486-linux-gnu-gcc failed make: *** [MyWin.so] Error 2
Thanks, the example helped, i added in the dll main part. But im still getting the WinMain error and im convinced it has something to do with how im executing winemaker.
winemaker . --nosource-fix --dll --single-target MyWin --nomfc -I"." -L"." -iMyLinuxFunc
The new command line result of make is winegcc -c -I. -I. -o MyLinuxFunc.o MyLinuxFunc.c winegcc -c -I. -I. -o MyWin.o MyWin.c winegcc -o MyWin.so MyLinuxFunc.o MyWin.o -L. -lMyLinuxFunc /usr/lib/wine/libwinecrt0.a(exe_main.o): In function `main': (.text+0xa0): undefined reference to `WinMain' collect2: ld returned 1 exit status winegcc: i486-linux-gnu-gcc failed make: *** [MyWin.so] Error 2
The problem with doing -lMyLinuxFunc (where i have libMyLinuxFunc.so in the directory) is that for some reason the output i get when doing make is
seth@seth-laptop:~/devel/meta$ make winegcc -o MyWin.so MyLinuxFunc.o MyWin.o -L. MyLinuxFunc winegcc: File does not exist: MyLinuxFunc make: *** [MyWin.so] Error 2
and the -L. is there to indicate the directory my library is in. Ive looked up the winmain error and it looks like it appears that im attempting to build a winmain application instead of a dll? How do i specify a dll?
Im using wine1.2-dev and wine1.2 (well actually it says to the right that its 1.1.42 installed version) from the lucid 10.04 ubuntu repositories.
Well, adding the -shared worked! Thanks! Is there any way i can get winemaker to do this automatically? I thought the -dll option would work?
Am 16.06.2010 15:50, schrieb Seth Burleigh:
Thanks, the example helped, i added in the dll main part. But im still getting the WinMain error and im convinced it has something to do with how im executing winemaker.
winemaker . --nosource-fix --dll --single-target MyWin --nomfc -I"." -L"." -iMyLinuxFunc
The new command line result of make is winegcc -c -I. -I. -o MyLinuxFunc.o MyLinuxFunc.c winegcc -c -I. -I. -o MyWin.o MyWin.c winegcc -o MyWin.so MyLinuxFunc.o MyWin.o -L. -lMyLinuxFunc /usr/lib/wine/libwinecrt0.a(exe_main.o): In function `main': (.text+0xa0): undefined reference to `WinMain' collect2: ld returned 1 exit status winegcc: i486-linux-gnu-gcc failed make: *** [MyWin.so] Error 2
The winemaker problem is something for me, i will look into it these days...
OK, so i have the dll built. However, it doesn't seem to be able to open. Let me explain, im using it in metatrader and so all im doing is moving the dll.so (and renamed it to MyWin.dll) to its libraries folder and doing an import statement in mql4. However, i then get a system error 'Cannot load MyWin.dll (error 126)'. Ive looked it up and that means 'The specified module could not be found' However, when checking its dependencies using ldd MyWin.dll, it says it has found all dependencies. So, is there something i need to do to register the dll so that it can be loaded properly?
Im assuming metatrader is using a dynamic loading scheme, though i don't really know.
Am 17.06.2010 04:52, schrieb Seth Burleigh:
OK, so i have the dll built. However, it doesn't seem to be able to open. Let me explain, im using it in metatrader and so all im doing is moving the dll.so (and renamed it to MyWin.dll) to its libraries folder and doing an import statement in mql4. However, i then get a system error 'Cannot load MyWin.dll (error 126)'. Ive looked it up and that means 'The specified module could not be found' However, when checking its dependencies using ldd MyWin.dll, it says it has found all dependencies. So, is there something i need to do to register the dll so that it can be loaded properly?
Im assuming metatrader is using a dynamic loading scheme, though i don't really know.
from the spec file there is a def file generated... change the def-file: replace "LIBRARY MyWin.dll.so" with "LIBRARY MyWin.dll" the run make again and you should get a dll which might be some more adaptive.
Thanks all! I got it to work! There was 2 mistakes with my thing - first, i had an empty definition for DllMain which caused the error 126 and then , well, i called the wrong function from metatrader. I shouldve been calling MyWinFunction. I guess i wasn't doing this because i wasn't seeing it when doing nm MyWin.dll.so, i guess all that magic is done by some wine functions in the dll which i see are there!