MSVC and MinGW DLLs | MinGW
Assume we have a testdll.h, testdll.c, and testmain.c. In the first case, we will compile testdll.c with MinGW, and let the MSVC-compiled testmain call it. You should use
gcc -shared -o testdll.dll testdll.c -Wl,--output-def,testdll.def,--out-implib,libtestdll.a
to produce the DLL and DEF files. MSVC cannot use the MinGW library, but since you have already the DEF file you may easily produce one by the Microsoft LIB tool:
lib /machine:i386 /def:testdll.def
Once you have testdll.lib, it is trivial to produce the executable with MSVC:
cl testmain.c testdll.lib
Now for MinGW programs calling an MSVC DLL. We have two methods. One way is to specify the LIB files directly on the command line after the main program. For example, after
cl /LD testdll.c
use
gcc -o testmain testmain.c testdll.lib
The other way is to produce the .a files for GCC. For __cdecl functions (in most cases), it is simple: you only need to apply the reimp tool from Anders Norlander (since his web site is no longer available, you may choose to download [this version|http://jrfonseca.dyndns.org/projects/gnu-win32/software/reimp/index.html] enhanced by Jose Fonseca):
reimp testdll.lib
gcc -o testmain testmain.c -L. -ltestdll
However, for __stdcall functions, the above method does not work. For MSVC will prefix an underscore to __stdcall functions while MinGW will not. The right way is to produce the DEF file using the pexports tool included in the mingw-utils package and filter off the first underscore by sed:
pexports testdll.dll | sed "s/^_//" > testdll.def
Then, when using dlltool to produce the import library, add `-U' to the command line:
dlltool -U -d testdll.def -l libtestdll.a
And now, you can proceed in the usual way:
gcc -o testmain testmain.c -L. -ltestdll
Hooray, we got it.
Saturday, November 07, 2009
Tuesday, November 03, 2009
Build OpenCV 2.0.0a as static library
In MSVC++ 2008...
Use CMAKE to generate project files
From project files...
1. Change DLL option to LIB
2. Change OUTPUT folder to ..\..\lib\($env)\($projectName)200($d).lib
HIGHGUI200.LIB may build but no use (looking for solution now)...
Alternatevely use shared library of HIGHGUI200.LIB and place CXCORE200.DLL and HIGHGUI200.DLL on the path
To Compile custom project, make sure change /MT(d) to /MD(d) in compiler option and set /NODEFAULTLIB:"libcmt(d).lib"
Use CMAKE to generate project files
From project files...
1. Change DLL option to LIB
2. Change OUTPUT folder to ..\..\lib\($env)\($projectName)200($d).lib
HIGHGUI200.LIB may build but no use (looking for solution now)...
Alternatevely use shared library of HIGHGUI200.LIB and place CXCORE200.DLL and HIGHGUI200.DLL on the path
To Compile custom project, make sure change /MT(d) to /MD(d) in compiler option and set /NODEFAULTLIB:"libcmt(d).lib"
Build Qt as static library
set qmakespec=(win32-g++ or win32-msvc2008 ...)
configure -release -static -no-exceptions -graphicssystem opengl -nomake examples -nomake demos
configure -release -static -no-exceptions -graphicssystem opengl -nomake examples -nomake demos
Open CV 1.1pre1 MINGW 5.1.6 (GCC 3.4.5) Compile
ren bin bin_original // back up original files
ren lib lib_original // back up original files
cd _make
mingw32-make -f make_all_gnu.mak // for release version
set DEBUG=1
mingw32-make -f make_all_gnu.mak // for debug version
ren lib lib_original // back up original files
cd _make
mingw32-make -f make_all_gnu.mak // for release version
set DEBUG=1
mingw32-make -f make_all_gnu.mak // for debug version
Subscribe to:
Posts (Atom)