PDA

View Full Version : mingw link with msvc dll



jhowland
21st October 2010, 21:52
I know similar questions have been asked many times, and I have been through all of the answers I could find as best as I can...given that few of them are real specific. I have tried all of the suggestions I could find, to no avail. I am hoping that somebody will have something new to add given the specifics I describe.

I am using a library made by Prosilica ( camera manufacturer--they have been acquired by Allied Vision, but it is still a "Prosilica" library). They provide a dll named PvAPI.dll, as well as a library called PvAPI.lib--apparently for Microsoft Visual Studio 6.0. These are described by Prosilica as "a standard call dll, which is accessible by most programming languages". Prosilica states that "Most compilers come with a tool to generate an import library from a DLL; see your compiler's manual for more information."

I have successfully used this library with various versions of MS Visual Studio and QT for some time. Now, however, I am trying to transition away from MS development tools due to the difficulties in distribution of software when using MS tools. I am very happy with Creator/Mingw, with the sole exception (so far) that I have been unable to use the Prosilica dll.

I have tried using pexports to produce a .def file, and dlltool to make a .a file--the result is undefined references to the Prosilica functions. I have tried using a .def file provided by Prosilica--same result


I have tried using reimp to convert the .lib, and I get "invalid or corrupt import library" error messages.

Is there something else to try? Prosilica has little to offer.

Thanks in advance for any suggestions


Jonathan Howland

ChrisW67
21st October 2010, 23:28
If the Prosilica library is straight C-style interfaces (i.e. no name mangling) then you should be able to make this work. I gather that you have the necessary header files and that your code is compiling but failing to link. If the linker is not finding symbols check that you added the Prosilica library/library directory to the LIBS path.

Otherwise this page (http://www.mingw.org/wiki/MSVC_and_MinGW_DLLs) described the need to post-process the pimport output for stdcall libraries.


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

emigrand
1st April 2012, 19:58
Hi, as a newbie I am not sure if I am really dealing with the same problem, but I assume it goes into the same direction:
I am also trying to use an AVT library to access a "Pike" camera by Allied Vision. In VS2010 everything worked perfect, but I can't get it running in QT, even when I reduce the code to a minimal console application:

.pro:


QT += core
QT -= gui

INCLUDEPATH += C:/FirePackage/FireGrab/Lib
LIBS += C:/FirePackage/FireGrab/Lib/FGCamera.lib
LIBS += C:/FirePackage/FireGrab/Lib/FGCamera.dll

TARGET = FirePackage_Console
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp

(please correct me if something is wrong)

main.cpp:


#include <QtCore/QCoreApplication>
#include <fgcamera.h>

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
CFGCamera Camera;
return a.exec();
}


In release mode, I get this:
:: error: collect2: ld returned 1 exit status

In debug mode the following:
:: error: undefined reference to '_imp__ZN9CFGCameraD1Ev'
:: error: undefined reference to '_imp__ZN9CFGCameraD1Ev'
:: error: undefined reference to '_imp__ZN9CFGCameraD1Ev'
:: error: collect2: ld returned 1 exit status

When I comment out the CFGCamera instantiation it compiles.
Are the library files somehow not compatible with QT? Is a "conversion" necessary/possible?? Can I do that as a non-programmer?

Maybe you can tell more if you have a look at the library? You can find it here (http://www.alliedvisiontec.com/fileadmin/content/PDF/Software/AVT_software/zip_files/AVTFirePackage_3v0.zip).
Thanks for your help!

d_stranz
1st April 2012, 20:48
but I can't get it running in QT

What does this mean? Qt isn't a compiler or linker. If you are no longer using MSVC, then the FGCamera.lib is probably not compatible with whatever compiler and linker you -are- using. I doubt it is necessary to add the .dll as one of the LIBS in the .pro file; it is run-time only, not used in compiling or linking.

The previous answer by ChrisW is probably exactly what you need to do to make a compatible .lib from the DLL.


When I comment out the CFGCamera instantiation it compiles.

It already -is- compiling successfully with that instantiation in place. What it isn't doing is -linking- to produce an executable file. When you comment out that line, you are removing any references to the camera code from the link requirements, regardless of whether or not you include the header file for the CFGCamera class. Once you include the instantiation, you've created a link-time dependency for it.

emigrand
1st April 2012, 22:04
What does this mean?
ok, sorry, I am using qt creator and the mingw compiler.


he previous answer by ChrisW is probably exactly what you need to do to make a compatible .lib from the DLL.
could you give me a hint where to start? or even better, would someone be so kind and create a lib file from the dll for me? The link doesn't help that much...

emigrand
2nd April 2012, 13:07
Sorry for bothering this part of the forum with newbie issues. Just wanted to tell that there seems to be a solution for my and maybe others' problems concerning this library:

On AVT's homepage I found the following:


The CFGCamera object of the MS VS C++ library FGCamera.lib could not be converted to MinGW compatible *.a library. That's why there's the C-wrapper FGWrap.dll providing the functions of the FireGrab interface to a camera handle instead of an CFGCamera object.


See here (http://www.alliedvisiontec.com/de/support/knowledge-base.html?tx_nawavtknowledgebase_piList[uid]=142&tx_nawavtknowledgebase_piList[mode]=single)for details.

Thanks for your help.