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. Can't link an external C dll
QtWS25 Last Chance

Can't link an external C dll

Scheduled Pinned Locked Moved General and Desktop
dll
6 Posts 4 Posters 2.4k 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.
  • F Offline
    F Offline
    Florian
    wrote on last edited by
    #1

    Hello,
    I have trouble linking an external C dll into a QtCreator project.
    In the library I'm using, I have a folder "include" containing some .h files, a folder "lib", containing only one .def file, and also have one .dll.

    My .pro looks like that:

    CONFIG+=console
    CONFIG+=c++11
    CONFIG-=app_bundle
    CONFIG-=qt
      
    DEF_FILE+="C:\MyLib\lib\MyLib.def"
      
    INCLUDEPATH+=C:\MyLib\include
      
    LIBS+=-LC:\MyLib\lib
      
    SOURCES+=\
    main.cpp
      
    include(deployment.pri)
    qtcAddDeployment()
    

    However, at compilation time, I have a lot of errors : "LNK2001: unresolved external symbol ..."
    These errors appear for the functions appearing in the .def file.

    I don't know what else I can do... I have very few experience linking library in QtCreator.

    Thanks for your help

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christopher
      wrote on last edited by
      #2
      LIBS+=-LC:\MyLib\lib -lMyLib
      

      You also have to tell the compiler to use the MyLiblibrary with -lMyLib argument

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Florian
        wrote on last edited by
        #3

        Thank you for your answer.

        However, I don't have any .lib file. In the "lib" folder, all I have is a .def file.

        If I add the line you mentioned, the compiler says: LNK1104: cannot open file 'MyLib.lib'

        1 Reply Last reply
        0
        • ad1170A Offline
          ad1170A Offline
          ad1170
          wrote on last edited by
          #4

          Hello,

          try to make the LIB from DEF File:

          lib /machine:x86 /def:yourDef.def /out:yourlib.lib

          (i use lib.exe from VisualStudio)

          Regards

          1 Reply Last reply
          1
          • sneubertS Offline
            sneubertS Offline
            sneubert
            wrote on last edited by
            #5

            Hi Florian,

            the .def file contains the names of the exported function in the .dll.
            To get a .lib for importing in you project as Christopher suggested you need the lib-Tool
            from Microsoft Visual Studio.
            Once you have Visual Studio you can open a "Visual Studio Command Prompt" and type

            lib.exe /def:C:\MyLib\lib\MyLib.def /OUT:C:\MyLib\lib\MyLib.lib
            
            1 Reply Last reply
            1
            • F Offline
              F Offline
              Florian
              wrote on last edited by Florian
              #6

              Thank you very much to both of you, it's almost working perfectly.

              Now I only have two warnings:

              LNK4070: /OUT:Mylib.dll directive in .EXP differs from output filename 'debug\ProjectName.exe'; ignoring directive
              And in red it's written: File not found: ProjectName.exp

              I get MyLib.exp using lib.exe, that I put in the lib folder (I'm pretty sure it's not useful there), but it seems I also need a ProjectName.exp ?

              The second warning is even more weird to me:
              LNK4086: entrypoint '_mainCRTStartup' is not __stdcall with 12 bytes of arguments; image may not run

              Any idea of what could be the problem?

              EDIT: It seems to be okay now. I just remove the line "DEF_FILE+="C:\MyLib\lib\MyLib.def"" from my .pro, and everything seems to be working now :)

              Thank you again,
              Florian

              1 Reply Last reply
              0

              • Login

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