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. How to use 3-party .dll and .lib libraries on windows
Forum Updated to NodeBB v4.3 + New Features

How to use 3-party .dll and .lib libraries on windows

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.6k Views 1 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.
  • sun zuS Offline
    sun zuS Offline
    sun zu
    wrote on last edited by
    #1

    thoes libraries consists .dll .lib .h files, supposedly developed in an microsoft visual studio environment. And my qt is a newest 5.7 version, turns out the mingw compiler tool-chain can not recognize the .lib static library to my main program file, as a result I get "cant find reference" error for all the classes and functions defined by the .lib and .dll file. Can anybody give me some hint on How to compile and link this library in qt?

    kshegunovK 1 Reply Last reply
    0
    • sun zuS sun zu

      thoes libraries consists .dll .lib .h files, supposedly developed in an microsoft visual studio environment. And my qt is a newest 5.7 version, turns out the mingw compiler tool-chain can not recognize the .lib static library to my main program file, as a result I get "cant find reference" error for all the classes and functions defined by the .lib and .dll file. Can anybody give me some hint on How to compile and link this library in qt?

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by
      #2

      Hello @sun-zu,
      You must use the same compiler as the one employed for the dll/lib file. Compilers are not interchangeable and might not even be compatible between versions, so you have to match the version of the compiler as well.

      Kind regards.

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      1
      • sun zuS Offline
        sun zuS Offline
        sun zu
        wrote on last edited by
        #3

        Thank you, I realise that, what troubling me more is that even I can't get QT5.7 to use the windows sdk 7.1 I have installed on my computer (which is compatible with codeblocks). That way, my problem falls on to how to setup gt5 so that I can choose windows sdk as its compiling toolchain? I can't find the documentation on related topics.

        kshegunovK 1 Reply Last reply
        0
        • sun zuS sun zu

          Thank you, I realise that, what troubling me more is that even I can't get QT5.7 to use the windows sdk 7.1 I have installed on my computer (which is compatible with codeblocks). That way, my problem falls on to how to setup gt5 so that I can choose windows sdk as its compiling toolchain? I can't find the documentation on related topics.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @sun-zu
          Hello,

          Do you meant these?
          http://doc.qt.io/qt-5/windows-requirements.html
          http://doc.qt.io/qt-5/windows-building.html

          Kind regards.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          1
          • R Offline
            R Offline
            Rondog
            wrote on last edited by
            #5

            If the third party library has all the symbols exported in C (not C++ mangled) then you have a couple of options for dynamically linking to your program:

            • Use windows specific API's

            • Use QLibrary

            In Win32 it would be something like this:

            	typedef BOOL (__cdecl *Some_Exported_Function)(DWORD); // signature. returns MS bool and takes DWORD parameter
            	
            	Some_Exported_Function	some_function;
            	HINSTANCE hInstance_dll = LoadLibrary(L"name_of_library.dll");
            	some_function = (Some_Exported_Function) GetProcAddress(hInstance_dll, "Some_Function");
            
            	if(FALSE == (some_function)(123))
            	{
            		// returned false;
            	}
            	FreeLibrary(hInstance_dll);
            

            Using QLibrary (from the Qt help):

            	QLibrary myLib("mylib");
            	typedef void (*MyPrototype)();
            	MyPrototype myFunction = (MyPrototype) myLib.resolve("mysymbol");
            	if (myFunction)
            		myFunction();
            	myLib.unload();
            

            The compiler won't matter in this case. I have no issues using this method to run functions compiled in a DLL from an older MSVC system (2003?) and accessing with a newer version of MinGW. This assumes the function names in the DLL are not mangled (if it is a third party library they probably shouldn't be).

            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