Can't link an external C dll



  • 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



  • LIBS+=-LC:\MyLib\lib -lMyLib
    

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



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



  • 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



  • 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
    


  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.