Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Building with dll (canbus driver)
Forum Updated to NodeBB v4.3 + New Features

Building with dll (canbus driver)

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 723 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MScottM
    wrote on last edited by
    #1

    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.)

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • M Offline
        M Offline
        MScottM
        wrote on last edited by
        #3

        Hi @Christian-Ehrlicher,

        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?'

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Your LIBS line is still wrong. The link you posted properly explains what -L and -l has to be used for.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1
          • K Offline
            K Offline
            kuzulis
            Qt Champions 2020
            wrote on last edited by
            #5

            There are (in qt code review) exists a pending patch for KVaser support. You can take a code from there. Besides, you can also help to submit that patch.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MScottM
              wrote on last edited by
              #6

              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.

              Christian EhrlicherC 1 Reply Last reply
              0
              • M MScottM

                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.

                Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @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.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                2
                • M Offline
                  M Offline
                  MScottM
                  wrote on last edited by
                  #8

                  Yes! It built. Thank you for the help!!

                  1 Reply Last reply
                  1

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved