
A1.2 Adding C/C
++
code: a simple dynamic link library 5
A1.2.1.5 Compilation on Unix platforms
Current versions of Ox for Linux (on Intel machines), SunOS and all other Unix plat-
forms support dynamic linking. Compiling and using the threes example works very
similarly on these platforms as under Windows. The Unix installation notes, are also
relevant when you produce your own DLLs.
For the Linux platform, for example, the threes code is compiled by executing the
command
make -f threes.mak
which creates threes.so. The header file oxexport.h and dependencies must be in the
search path.
1
Then run
oxl threes
to see if it works. The dynamic linker must be able to find threes.so, as discussed in the
Unix installation notes. Unix platforms do not use name decoration of C functions.
A1.2.2 Calling the Dynamic Link Library
After creating the DLL, the function can be used as follows:
.................................................ox/dev/windows/threes/threes.ox
#include <oxstd.h>
extern "Visual C++ 6/threes,FnThrees"
Threes(const r, const c);
main()
{
print(Threes(3,3));
}
.......................................................................................
The function is declared as extern, with the DLL file in Visual C++ 6/threes.
The name of the function in threes.dll is FnThrees, but in our Ox code we wish
to call it Threes. After this declaration, we can use the function Threes as any other
standard library function.
If the program does not work, check the requirements to successfully link to the Ox
DLL under Windows on the Intel platform:
• standard call (
stdcall) calling convention;
this pushes parameters from right to left, and lets the function clean the stack;
• structure packing at 8 byte boundaries,
• flat 32-bit memory model.
Make sure that FnThrees is the exact name in the DLL file; some compilers will
change the name according to the calling convention (and C
++
functions could be
subject to name mangling).
1
On some platforms there may be unresolved messages from the linker, which can be ignored.
Commentaires sur ces manuels