How do you add a library in QT

  • All I am trying to do is add OpenCL to a QT project. My OpenCL files are in



    According to what I read "here": if you have a .lib and a .dll you should link dynamically and I do have a .dll.


    I setup my .pro file:

    @LIBS += -lOpenCL
    LIBS += -LC:/opencl/lib/x86
    INCLUDEPATH += C:/opencl/include@

    I include the header file:

    @#include <CL/cl.h>@

    QT intellisense incorporates the header file


    The application builds and runs fine. However, as soon as I try to call any of the functions in the library I get linker errors:

    @LNK2019: unresolved external symbol clGetPlatformIDs referenced in function main
    LNK1120: 1 unresolved externals@

  • Moderators

    2 potential solutions I see here:

    • linkers are sequential - they include the libraries in the order you specify. In your case, you are including the libfile (small 'L') before you specify the folder that contains it (big 'L'). Swap those 2 lines and it could work
    • on Windows, you can actually specify the path to your .lib file without any '-l' or '-L': LIBS += C:/opencl/lib/x86/OpenCL.lib

  • Good guess but it's a nogo. Neither attempt worked.

    @LIBS += "C:/opencl/lib/x86/OpenCL.lib"
    INCLUDEPATH += C:/opencl/include@

    @LIBS += -LC:/opencl/lib/x86
    LIBS += -lOpenCL
    INCLUDEPATH += C:/opencl/include@

  • I finally figured this out (with some help).

    I installed QT 64-bit. Then I linked to OpenCL 64 bit (did not realize it but I was linked to 32 bit OpenCL before).

  • Moderators

    Uh, very good find. 64/32 bit mismatches are sometimes hard to notice.

Log in to reply

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