Chapter 5. Using Linux libraries as DLLs

Table of Contents
5.1. Introduction
5.2. Writing the spec file
5.3. How to deal with C++ APIs
5.4. Writing the wrapper
5.5. Building
5.6. Installing
5.7. Advanced options

5.1. Introduction

For one reason or another you may find yourself with a Linux shared library that you want to use as if it were a Windows Dll. There are various reasons for this including the following:

The process for dealing with these situations is actually quite simple. You need to write a spec file that will describe the library's interface in the same format as a Dll (primarily what functions it exports). Also you will want to write a small wrapper around the library. You combine these to form a Wine built-in Dll that links to the Linux library. Then you modify the DllOverrides in the wine config file to ensure that this new built-in DLL is called rather than any windows version.

In this section we will look at two examples. The first example is extremely simple and leads into the subject in "baby steps". The second example is the ODBC interface proxy in Wine. The files to which we will refer for the ODBC example are currently in the dlls/odbc32 directory of the Wine source.

The first example is based very closely on a real case (the names of the functions etc. have been changed to protect the innocent). A large Windows application includes a DLL that links to a third-party DLL. For various reasons the third-party DLL does not work too well under Wine. However the third-party DLL is also available for the Linux environment. Conveniently the DLL and Linux shared library export only a small number of functions and the application only uses one of those.

Specifically, the application calls a function:
signed short WINAPI MyWinFunc (unsigned short a, void *b, void *c,
        unsigned long *d, void *e, unsigned char f, char g,
        unsigned char *h);
and the linux library exports a corresponding function:
signed short MyLinuxFunc (unsigned short a, void *b, void *c,
        unsigned short *d, void *e, char g, unsigned char *h);