Reputation: 339
I am trying to use the oracle oci library with the compiler mingw64. If I link the oci.lib provided by oracle, my 64bit program crashes, because apparently mingw64 does not support linking with dll created with vc.
The workaround for this seems to be:
1) generate a def file from the oci.dll, which i am doing with mingw64 gendef (if I use this command "dlltool -z oci.def --export-all-symbol oci.dll" I get an empty def file, while if I use gendef I get a populated def file)
2) generate a import library oci.a with dlltool ("dlltool -d oci.def -l liboci.a")
however the oci.a library that I generate with dlltool is an empty file. In other works it seems that I am not able to generate this oci.a library, that I should use to link my program to the oci.dll
Does someone know how to solve this issue? Is someone able to perform this task correctly?
Thank you
Marco
Upvotes: 1
Views: 2606
Reputation:
This post may not apply to 64 bit systems for all I know, but it works on 32 bit Windows...
I tried GENDEF, and it failed to produce a DEF file. Having already solved this problem for my own purposes in beginning to write DLL's, I suggest using Tiny_impdef.exe from TCC, which works. (TCC = Tiny C Compiler, by Fabrice Bellard, and later, Grishka.) What's more, unlike DLLTOOL (and possibly GENDEF), it works whether GCC used -s to strip the output DLL or not!
Use DLLTOOL to generate the *.a library file from the DEF, if using GCC. TCC will do the entire build of DLL and EXE, using just two command lines. I have a set of commands that will allow either the DLL, or the EXE, to be built by GCC, or TCC, with all four possible combinations working.
Batch file below, for plundering at will... I'm sure it can be bettered, but at least it works cleanly as is.
@ECHO OFF REM This system seems to work regardless of which compiler makes the DLL or the EXE. Try to simplify for GCC.For completeness, here's the C code for the test DLL:REM TCC COMMANDS. Creates 3 files, DLL and DEF, then EXE. REM E:\CODING\TCC\TCC.EXE -shared E:\CODING\TCC\EXAMPLES\Test_DLL\Test_DLL.c -oE:\CODING\TCC\EXAMPLES\Test_DLL\Test_DLL.dll REM E:\CODING\TCC\TCC.EXE E:\CODING\TCC\EXAMPLES\Test_DLL\Test_EXE.c E:\CODING\TCC\EXAMPLES\Test_DLL\Test_DLL.def -oE:\CODING\TCC\EXAMPLES\Test_DLL\Test_DLL.exe
REM GCC COMMANDS. WARNING! Still needs TCC's Tiny_Impdef.exe! E:\CODING\GCC\BIN\GCC.EXE -s -shared -IE:\CODING\GCC\INCLUDE -mwindows E:\CODING\TCC\EXAMPLES\Test_DLL\Test_DLL.c -oE:\CODING\TCC\EXAMPLES\Test_DLL\Test_DLL.dll E:\CODING\TCC\"Tiny_Impdef.exe" E:\CODING\TCC\EXAMPLES\TEST_DLL\TEST_DLL.DLL > NUL E:\CODING\GCC\MINGW32\BIN\DLLTOOL.EXE -d E:\CODING\TCC\EXAMPLES\Test_DLL\Test_DLL.def -lE:\CODING\TCC\EXAMPLES\Test_DLL\libTest_DLL.a E:\CODING\GCC\BIN\GCC.EXE -s -IE:\CODING\GCC\INCLUDE -mwindows E:\CODING\TCC\EXAMPLES\Test_DLL\Test_EXE.c E:\CODING\TCC\EXAMPLES\Test_DLL\libTest_DLL.a -oE:\CODING\TCC\EXAMPLES\Test_DLL\Test_DLL.exe
START E:\CODING\TCC\EXAMPLES\Test_DLL\Test_DLL.exe
#include <windows.h>
#define DLL_EXPORT __declspec(dllexport)
DLL_EXPORT void ZoodleWurdle(){
MessageBox (0, "Wurdle", "Zoodle", MB_ICONINFORMATION);
}
DLL_EXPORT void MangleWurzel(){
MessageBox (0, "Mangled", "Wurzels", MB_ICONINFORMATION);
}
Sorry about the Gummidgisms, but I had to start somewhere, and I never liked foo and bar, or hello and world... Here's the EXE:
#include <windows.h>
void ZoodleWurdle();
void MangleWurzel();
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow){
ZoodleWurdle(); MangleWurzel();
return 0;
}
Upvotes: 1
Reputation: 17021
I've just generated liboci.a
without any troubles. Probably you messed up something or used incorrect approach (dlltool -z ...
). Here is how you do it:
Download and install (can build from source) gendef
utility:
Run gendef oci.dll
(will generate oci.def
);
Run dlltool -D oci.dll -d oci.def -l liboci.a
(will generate liboci.a
);
Now try to link against liboci.a
.
NOTE: Please, make sure that if your oci.dll
is targeted at x86, then dlltool
should be from the MinGW/MinGW-w64 distribution that is targeting x86 as well. The same goes for x64 case, i.e. it is important that targeted architectures match.
Upvotes: 2