Building with dll (canbus driver)
-
Hi all,
So I have a new (to me) Kvaser CANBUS cable, and I'm trying to get this to build so I can add some of my own functionality to it. I've never tried to build using a 3rd party dll before, though I have read through this.
I'm using Qt6, I've tried to build it with MSCV2019 and MinGW. With MSCV, the error I get is 'LNK2019 unresolved external symbol...' for each of the functions that have to do with the CAN cable. When I try with MinGW, it is 'undefined reference to...' each of the same functions.
I had to add these lines to the .pro file to even get it this far (I created the directory for the .dll and put it in there):
INCLUDEPATH += ../libs LIBS += -Lcanlib32.dll \
Without them, there were over 1k issues when trying to build.
Is there some way I can get this to build? Do I have to recompile the Kvaser software source (something I've never tried before)? Any thoughts on how to proceed appreciated!
(Oh - the executable from the Git page does work - it sees my cable and I can interact with it.)
-
You don't link against a DLL but against a static import lib (msvc: <libname>.lib, mingw: <libname>.a) - fix your
LIBS +=
line to link against the proper import lib.
Is the dll a plain c dll or does it export c++ classes? In the latter case you have to use the correct for your compiler since the c++ MSVC and MinGW ABI are no compatible. -
The Kvaser SDK has a *.lib file but no *.a files, so I copied the canlib32.lib file (from the kvaser SDK) into the folder and changed the line to:
LIBS += -Lcanlib32.lib
Then did a clean, and tried to build again with MSCV, the errors seem to be exactly the same. Does that mean I have to somehow create a *.a file from their source code?
I'm not sure about the second part of your answer - 'Is the dll a plain c dll or does it export c++ classes?'
-
Your LIBS line is still wrong. The link you posted properly explains what
-L
and-l
has to be used for. -
Okay, I changed the LIBS line to:
LIBS += -L../libs -lcanlib32
and this time there is only one error...well, two, but they are related:
moc_mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: void __cdecl MainWindow::receiveQmlFrame(class QString const &,class QString const &)const " (?receiveQmlFrame@MainWindow@@QEBAXAEBVQString@@0@Z) referenced in function "public: virtual int __cdecl MainWindow::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@MainWindow@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
I'm trying to sort whether this is fixable in the code?
@kuzulis - native support for Kvaser would be amazing! I'll take a look at it.
-
Okay, I changed the LIBS line to:
LIBS += -L../libs -lcanlib32
and this time there is only one error...well, two, but they are related:
moc_mainwindow.obj:-1: error: LNK2019: unresolved external symbol "public: void __cdecl MainWindow::receiveQmlFrame(class QString const &,class QString const &)const " (?receiveQmlFrame@MainWindow@@QEBAXAEBVQString@@0@Z) referenced in function "public: virtual int __cdecl MainWindow::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@MainWindow@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
I'm trying to sort whether this is fixable in the code?
@kuzulis - native support for Kvaser would be amazing! I'll take a look at it.
@MScottM said in Building with dll (canbus driver):
I'm trying to sort whether this is fixable in the code?
You declared a slot function in your MainWindow class but did not provide an implementation.