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. Using 3rd party dll with defined global variables
Forum Updated to NodeBB v4.3 + New Features

Using 3rd party dll with defined global variables

Scheduled Pinned Locked Moved Solved General and Desktop
14 Posts 5 Posters 2.0k Views 2 Watching
  • 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.
  • S Offline
    S Offline
    sykac
    wrote on last edited by sykac
    #1

    Hi,
    I'm building an app which needs some 3rd party .dll files. I linked the appropriate .lib files in my .pro file, set INCLUDEPATH for the headers, placed .dlls to the build directory, but now I'm having troubles building my application. The problem seems to be that there are global variables used in the headers (extern type glvbalVar; someLocalVar = globalVr;) which are defined in the .dll .c files and I'm getting Unresolved external symbol errors for these global variables. Now I'm not sure if the problem is that the application cannot find the .dlls (it should, if they are in the build dir, shouldn't it?) or it's the problem of these global variables which are not known during the building (I'm not really sure how it works). So please could someone help me about what are the possibilities here?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      If your app is c++
      and the files truly are c files. ( not cpp)
      you might need to do
      extern "C" {
      #include "whatever.h"
      }
      so the names are not mangled.
      but its hard to say as im not sur what the lib/Dlls are.
      or where the error comes.

      it could also just be it dont link the libs.

      Jsut to be sure. You did compile the DLL with same compiler as for apps?
      if you downloaded them as binary.
      Are you using a compiler that is compatible with the one used to Create the libs/Dlls?
      Like you cannot use a DLL from Visual Studio 2013 in Vs 2017 etc.

      1 Reply Last reply
      3
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        can you post your .pro file?

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sykac
          wrote on last edited by sykac
          #4

          The .dlls are 3rd party, I just downloaded them and have no idea what compiler made them, so it could be the problem. If it is so, do I even have some chance to compile it?

          About the headers:
          My app is cpp. The problem headers (which are 3rd party and so not made by myself) are for c files and there is this in the headers:

          ifdef __cplusplus
          extern "C" {
          endif
          
          extern const int A;
          
          #ifdef __cplusplus
          } // extern "C"
          
          static const int B = A;
          
          endif
          

          And my .pro file. There are both the .lib and .dll in x64/lib. I copied the .dlls also to the build directory.

          TEMPLATE = app
          TARGET = test_xsens
          INCLUDEPATH += .
          
          CONFIG += console
          
          DEFINES += QT_DEPRECATED_WARNINGS
          
          DEFINES += XSENS_RELEASE
          DEFINES += XSTYPES_STATIC_LIB
          
          LIBS += -L$$PWD/x64/lib/ -lxstypes64
          LIBS += -L$$PWD/x64/lib/ -lxsensdeviceapi64
          
          INCLUDEPATH += $$PWD/include
          INCLUDEPATH += $$PWD/include/xsens
          INCLUDEPATH += $$PWD/include/xcommunication
          
          HEADERS += .....
          SOURCES += .....
          
          1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi
            Are you using visual studio compiler ?

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sykac
              wrote on last edited by
              #6

              Yes, I'm using msvc.

              mrjjM 1 Reply Last reply
              0
              • S sykac

                Yes, I'm using msvc.

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @sykac
                Where you download the library from.
                Dont it mention what compilers are supported ?

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  sykac
                  wrote on last edited by
                  #8

                  @mrjj
                  I downloaded it from the official web pages of the hardware the library is for. I checked everywhere and didn't find anything about supported compilers.

                  But I just found that there are the problem causing .c files in the library so I compilled them and used the rest of the library from the .dlls. It seems to be working, but I'm facing some runtime heap problems with some methods from the library. I don't know if it is connected to these linking and library problem which this question is about. I need to examine it a little bit more.

                  mrjjM 1 Reply Last reply
                  0
                  • S sykac

                    @mrjj
                    I downloaded it from the official web pages of the hardware the library is for. I checked everywhere and didn't find anything about supported compilers.

                    But I just found that there are the problem causing .c files in the library so I compilled them and used the rest of the library from the .dlls. It seems to be working, but I'm facing some runtime heap problems with some methods from the library. I don't know if it is connected to these linking and library problem which this question is about. I need to examine it a little bit more.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @sykac
                    Hi
                    It does sound like a c type library which can be used from
                    other compilers since no object/class types need be resolved.

                    Im not sure if you mixing would cause heap issues but make sure not mixing
                    debug and release modes as that might fool it.

                    Do you have all code for the DLLs ?

                    1 Reply Last reply
                    1
                    • S Offline
                      S Offline
                      sykac
                      wrote on last edited by
                      #10

                      No, that's the problem. I have only some files, the rest is only in the dlls. And the class ending with heap corruption is not from the files I have source code of, it's just in a dll so I cannot check what's happening there.

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        sykac
                        wrote on last edited by
                        #11

                        @mrjj
                        And what do you mean by mixing debug and release modes? (I'm using just the Debug mode in qtcreator)

                        jsulmJ 1 Reply Last reply
                        0
                        • S sykac

                          @mrjj
                          And what do you mean by mixing debug and release modes? (I'm using just the Debug mode in qtcreator)

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @sykac Is this lib build in debug or release mode?
                          Usually it is not a good idea to mix binaries build in debug and release mode.

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          3
                          • S Offline
                            S Offline
                            sykac
                            wrote on last edited by
                            #13

                            @jsulm
                            That was it. I built my app in release mode and now it works fine :-) Thank you very much.

                            Pablo J. RoginaP 1 Reply Last reply
                            1
                            • S sykac

                              @jsulm
                              That was it. I built my app in release mode and now it works fine :-) Thank you very much.

                              Pablo J. RoginaP Offline
                              Pablo J. RoginaP Offline
                              Pablo J. Rogina
                              wrote on last edited by
                              #14

                              @sykac if your issue is solved, please don't forget to mark your post as such. Thanks.

                              Upvote the answer(s) that helped you solve the issue
                              Use "Topic Tools" button to mark your post as Solved
                              Add screenshots via postimage.org
                              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                              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