Linking .lib and .dll
Posted: Sun Nov 10, 2013 3:05 am
Hi,
I'm running Windows 7 using MinGW-4.7.1 and version 5.3 of codelite.
I have an SDK in the form of a .dll, .lib, and .def (created by MSVC) that I need to use in a program I'm writing. I also have the .h file (which I #include in my program) that goes with these, but besides that the only documentation is a pdf list of the included functions.
I have tried several approaches to linking the library, but all have been successful - resulting in
errors or MinGW being unable to find the library depending on how I've set the project settings.
In project settings I have set the library path explicitly for the linker, the .dll is in my folder where the executable should appear, and I have tried giving the library name in several different ways. One approach was to link the library as libfli.lib. This results in
It is complaining that it cannot find -lfli.lib, yet I have read in the MinGW documentation that MinGW should now be able to handle .lib files by compiling with the -llib flag (see http://www.mingw.org/wiki/Specify_the_l ... ker_to_use) rather than the usual -l. Is there some way to set codelite to use -llib when I give it a library ending in .lib?
I have also read that to use libraries created in MSVC with MinGW, you can use MinGW's pexports and dlltool to create a library ending in the .a extension. This was my second approach. I followed the instructions here: http://www.mingw.org/wiki/MSVC_and_MinGW_DLLs
and created libfli.a, entered libfli as the library to link and I then get this error (actually every call to a function in the library is undefined, but I've commented the others out so the build log is easier to read).
What am I missing or how can I use the functions provided by this library which was created in MSVC?
Thanks,
Will
I'm running Windows 7 using MinGW-4.7.1 and version 5.3 of codelite.
I have an SDK in the form of a .dll, .lib, and .def (created by MSVC) that I need to use in a program I'm writing. I also have the .h file (which I #include in my program) that goes with these, but besides that the only documentation is a pdf list of the included functions.
I have tried several approaches to linking the library, but all have been successful - resulting in
Code: Select all
undefined reference to `_imp__*@#'
In project settings I have set the library path explicitly for the linker, the .dll is in my folder where the executable should appear, and I have tried giving the library name in several different ways. One approach was to link the library as libfli.lib. This results in
Code: Select all
C:\Windows\system32\cmd.exe /c "mingw32-make.exe -j 8 -e -f Makefile"
"----------Building project:[ v_0 - Debug ]----------"
mingw32-make.exe[1]: Entering directory `C:/Users/Documents/Software/CameraController/v_0'
g++ -o ./Debug/v_0 @"v_0.txt" -L. -LC:/Users/Documents/Software/CameraController/libfli-1.104-winbin -lfli.lib -mthreads -LC:/wxWidgets-2.9.5/lib/gcc_dll -lwxmsw29ud_xrc -lwxmsw29ud_aui -lwxmsw29ud_html -lwxmsw29ud_adv -lwxmsw29ud_core -lwxbase29ud_xml -lwxbase29ud_net -lwxmsw29ud_richtext -lwxbase29ud -lwxtiffd -lwxjpegd -lwxpngd -lwxzlibd -lwxregexud -lwxexpatd -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwxregexud -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -mwindows
c:/mingw-4.7.1/bin/../lib/gcc/mingw32/4.7.1/../../../../mingw32/bin/ld.exe: cannot find -lfli.lib
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[1]: *** [Debug/v_0] Error 1
v_0.mk:79: recipe for target `Debug/v_0' failed
mingw32-make.exe[1]: Leaving directory `C:/Users/Documents/Software/CameraController/v_0'
mingw32-make.exe: *** [All] Error 2
Makefile:4: recipe for target `All' failed
0 errors, 0 warnings
I have also read that to use libraries created in MSVC with MinGW, you can use MinGW's pexports and dlltool to create a library ending in the .a extension. This was my second approach. I followed the instructions here: http://www.mingw.org/wiki/MSVC_and_MinGW_DLLs
and created libfli.a, entered libfli as the library to link and I then get this error (actually every call to a function in the library is undefined, but I've commented the others out so the build log is easier to read).
Code: Select all
C:\Windows\system32\cmd.exe /c "mingw32-make.exe -j 8 -e -f Makefile"
"----------Building project:[ v_0 - Debug ]----------"
mingw32-make.exe[1]: Entering directory `C:/Users/Documents/Software/CameraController/v_0'
mingw32-make.exe[1]: Leaving directory `C:/Users/Documents/Software/CameraController/v_0'
mingw32-make.exe[1]: Entering directory `C:/Users/Documents/Software/CameraController/v_0'
g++ -c "C:/Users/Documents/Software/CameraController/v_0/MainFrame.cpp" -g -O0 -Wall -mthreads -DHAVE_W32API_H -D__WXMSW__ -D__WXDEBUG__ -D_UNICODE -IC:/wxWidgets-2.9.5/lib/gcc_dll/mswud -IC:/wxWidgets-2.9.5/include -DWXUSINGDLL -Wno-ctor-dtor-privacy -pipe -fmessage-length=0 -fno-keep-inline-dllexport -DSVN_REVISION=\"\" -o ./Debug/MainFrame.o -I. -IC:/CDSDK/inc
g++ -o ./Debug/v_0 @"v_0.txt" -L. -LC:/Users/Documents/Software/CameraController/libfli-1.104-winbin -lfli -mthreads -LC:/wxWidgets-2.9.5/lib/gcc_dll -lwxmsw29ud_xrc -lwxmsw29ud_aui -lwxmsw29ud_html -lwxmsw29ud_adv -lwxmsw29ud_core -lwxbase29ud_xml -lwxbase29ud_net -lwxmsw29ud_richtext -lwxbase29ud -lwxtiffd -lwxjpegd -lwxpngd -lwxzlibd -lwxregexud -lwxexpatd -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lwxregexud -lwinspool -lwinmm -lshell32 -lcomctl32 -lole32 -loleaut32 -luuid -lrpcrt4 -ladvapi32 -lwsock32 -mwindows
./Debug/MainFrame.o: In function `ZN9MainFrame11onTakeImageER14wxCommandEvent':
C:/Users/Documents/Software/CameraController/v_0/MainFrame.cpp:77: undefined reference to `_imp__FLIGetLibVersion@8'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[1]: *** [Debug/v_0] Error 1
v_0.mk:79: recipe for target `Debug/v_0' failed
mingw32-make.exe[1]: Leaving directory `C:/Users/Documents/Software/CameraController/v_0'
mingw32-make.exe: *** [All] Error 2
Makefile:4: recipe for target `All' failed
1 errors, 0 warnings
Thanks,
Will