This is my first post here, please excuse any incorrect terms etc. I have tried to follow chapter 5 of winelib-guild.pdf, but found winemaker does not correspond to the pdf.
I am using wine version 1.0-rc1. I am trying to call a Linux shared library from an unmodified windows C++ program using a “C” interface to a DLL. I have built very simple test case that I would like help to compile. Sorry for long post.
File 1. header file to define the interface between the windows program and windows DLL
#ifndef WINFUNC_H_
#define WINFUNC_H_
extern "C"
{
char * winFunc(bool select);
}
#endif /*WINFUNC_H_*/
File 2 – the windows program
#include <stdio.h>
#include "WinFunc.h"
int main(int argc, char * argv[])
{
char * str = winFunc(false);
printf("main: got %s\n", str);
}
File 3 – the windows DLL
#include "WinFunc.h"
#include <stdio.h>
__declspec(dllexport) char * winFunc(bool select)
{
if (select)
return "winString1";
else
return "winString2";
}
These have been compiled using MinGW on linux and produced files that work on windows, and with wine.
File 4. – Linux Shared library header
#ifndef LINUXFUNC_H_
#define LINUXFUNC_H_
extern "C"
{
char * linuxFunc(bool select);
}
#endif /*LINUXFUNC_H_*/
File 6 – Linux Shared library cpp
#include "LinuxFunc.h"
#include <stdio.h>
char * linuxFunc(bool select)
{
if (select)
return "linuxString1";
else
return "linuxString2";
}
File 5 and 6 compiled using gcc on linux.
File 7 – spec file for wine dll
@ stdcall winFunc (long)
File 8 – Library code#include "WinFunc.h"
#include "LinuxFunc.h"
#include <windef.h> /* Part of the Wine header files */
char * WINAPI winFunc(bool select)
{
return linuxFunc(select);
}
The spec file was processed with command
winebuild --dll --export=../WinToLinux.spec --external-symbols --subsystem=native --library-path=../../WinLib/Debug --output=Wrapper.o
The C++ code was compiled with command
wineg++ -I"/Work/work/workspace/Wine/WinLib" -I"/Work/work/workspace/Wine/LinuxLib" -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"WinToLinux.d" -MT"WinToLinux.d" -o"WinToLinux.o" "../WinToLinux.cpp"
And linked with
wineg++ -L"/Work/work/workspace/Wine/LinuxLib/Debug" -specs ../WinToLinux.spec -shared -o"WinToLinux.dll.so" ./WinToLinux.o ./Wrapper.o -lLinuxLib
But get the following error
./Wrapper.o(.data+0x0): In function `__wine_spec_nt_header':
: multiple definition of `__wine_spec_nt_header'
WinToLinux.dll-b7fdrU.spec.o(.data+0x0): first defined here
./Wrapper.o(.rodata+0x0): In function `__wine_spec_file_name':
: multiple definition of `__wine_spec_file_name'
WinToLinux.dll-b7fdrU.spec.o(.rodata+0x0): first defined here
./Wrapper.o(.data+0x28): In function `__wine_spec_nt_header':
: undefined reference to `null'
collect2: ld returned 1 exit status
winegcc: g++ failed
make: *** [WinToLinux.dll.so] Error 2
Question are.
1. What am I doing wrong or not doing?
2. Where can I find a how to?
3. Is this the correct approach?
The bigger picture is I need to share memory and other services between linux application and windows application, running at the same time.
Hopefully someone will be able to answer my questions or direct me to where I can find answers. I have tried Google but have had no luck.
If I would be better serviced by CodeWeaver, I am happy to go that way, But my view was that for this forum was the most suitable for this type of question.
Nev
problem build wine lib
Re: problem build wine lib
You missed 5.nev wrote:File 4. – Linux Shared library header
File 6 – Linux Shared library cpp
File 5 and 6 compiled using gcc on linux.
"--subsystem=native" is for "kernel drivers". You want "console" or "windows" depending on what your app does. That also meansnev wrote: The spec file was processed with command
winebuild --dll --export=../WinToLinux.spec --external-symbols --subsystem=native --library-path=../../WinLib/Debug --output=Wrapper.o
1) dunno winelib is not often used and only few people really know how to use it properly.nev wrote:Question are.
1. What am I doing wrong or not doing?
2. Where can I find a how to?
3. Is this the correct approach?
2) I doubt you will find one other then http://www.winehq.org/site/docs/winelib-guide/index
3) Not really. We've been discouraging anyone from using winelib for two main reasons:
- It's unstable and highly depends on Wine version. New Wine version might kill your app
- It's not portable to windows - you will have to maintain two separate codebases for your project.
If you want to port your application to Linux - fix Wine to work with your app.
If you really need some features not available on windows - write a native Linux application.
You can use number of different IPCs mechanisms available on Linux for this. Shared memory is the hardest to work with - it requires lots of synchronization if it's being modified.nev wrote:The bigger picture is I need to share memory and other services between linux application and windows application, running at the same time.
Thank you for your rely. All the files are listed, I just can not count. javascript:emoticon(':(')
SadNeither suggested option will work in my case.
I need to support BOTH Linux and Windows application running at the same time and have them share a small block of memory.
I have the Linux version up and running, and now need to enable the Windows version.
I require to use shared memory other IPC do not have the required features and/or performance.
I need the windows version because there is a large part that I do not have source. But I can write DLLs to become part of windows application.
I need to be able to do one of the following.
1. Share memory between the Linux app and the Windows app.
2. OR be able to call a Linux shared library from a Windows DLL. Primary purpose is to share memory.
I have found no reference to 1. any where in the documentation, It would appear that 2. must be possible because the documentation talks of wrapping a windows DLL inside a Linux shared library.
I read that as being this Linux can make any Linux shared libraries (because it is a Linux shared library) and wine will load this library as a windows DLL and other windows application can seamless access it.
Are my assumptions correct?
What tools should I use to build this “wrapper” shared library?
Any further suggestions?
Thank you again.
SadNeither suggested option will work in my case.
I need to support BOTH Linux and Windows application running at the same time and have them share a small block of memory.
I have the Linux version up and running, and now need to enable the Windows version.
I require to use shared memory other IPC do not have the required features and/or performance.
I need the windows version because there is a large part that I do not have source. But I can write DLLs to become part of windows application.
I need to be able to do one of the following.
1. Share memory between the Linux app and the Windows app.
2. OR be able to call a Linux shared library from a Windows DLL. Primary purpose is to share memory.
I have found no reference to 1. any where in the documentation, It would appear that 2. must be possible because the documentation talks of wrapping a windows DLL inside a Linux shared library.
I read that as being this Linux can make any Linux shared libraries (because it is a Linux shared library) and wine will load this library as a windows DLL and other windows application can seamless access it.
Are my assumptions correct?
What tools should I use to build this “wrapper” shared library?
Any further suggestions?
Thank you again.
problem build wine lib
nev skrev:
both.
You could always just create some disk file and mmap/MapViewOfFile it in1. Share memory between the Linux app and the Windows app.
both.
No.2. OR be able to call a Linux shared library from a Windows DLL. Primary purpose is to share memory.
I have found no reference to 1. any where in the documentation, It would appear that 2. must be possible because the documentation talks of wrapping a windows DLL inside a Linux shared library.
I read that as being this Linux can make any Linux shared libraries (because it is a Linux shared library) and wine will load this library as a windows DLL and other windows application can seamless access it.
What tools should I use to build this “wrapperâ€