Problem linking OpenCL



  • I work on a project and I must link the OpenCL library on Windows.
    When I use the QtCreator to add it (right click on project, in project tree/Add library), I get error “LNK2019: unresolved external symbol clGetPlatformID”
    The .pro file looks like this:

    @win32: LIBS += -L$$PWD/../../../../../Program Files/NVIDIA GPU Computing Toolkit/CUDA/v5.0/lib/Win32/ -lOpenCL

    INCLUDEPATH += $$PWD/../../../../../Program Files/NVIDIA GPU Computing Toolkit/CUDA/v5.0/lib/Win32
    DEPENDPATH += $$PWD/../../../../../Program Files/NVIDIA GPU Computing Toolkit/CUDA/v5.0/include

    win32: PRE_TARGETDEPS += $$PWD/../../../../../Program Files/NVIDIA GPU Computing --Toolkit/CUDA/v5.0/lib/Win32/OpenCL.lib@

    Also, I tried a different approach: I copied the OpenCL folder to C:\opencl because I thought that the white spaces in the file path may cause problems, but I still get the same errors.
    The .pro file for this approach looks like this:

    @win32:CONFIG(release, debug|release): LIBS += -Lc:/opencl/lib/Win32 -lOpenCL
    else:win32:CONFIG(debug, debug|release): LIBS += -Lc:/opencl/lib/Win32 -lOpenCL

    INCLUDEPATH += c:/opencl/include
    DEPENDPATH += c:/opencl/include@

    Another problem I get is when I try to include <CL/cl.h>.
    @C1083: Cannot open include file: 'CL/cl.h': No such file or directory.@

    I fixed this by copying the cl.h in the project, but this isn’t the best way.
    Any ideas of how to fix this?


  • Moderators

    welcome to devnet

    This looks like a compiler mismatch.
    Are you sure that the openCL lib is compiled with the same compiler and the same version as you are using in Qt creator as a tool chain?

    [quote author="mirror3000" date="1374788633"]
    @win32:CONFIG(release, debug|release): LIBS += -Lc:/opencl/lib/Win32 -lOpenCL
    else:win32:CONFIG(debug, debug|release): LIBS += -Lc:/opencl/lib/Win32 -lOpenCL

    INCLUDEPATH += c:/opencl/include
    DEPENDPATH += c:/opencl/include@
    [/quote]
    You are using the same LIBS statement for debug and release. If that is your intention, you can change to :
    @LIBS += -Lc:/opencl/lib/Win32 -lOpenCL
    @

    However, this may be also the basis of your problem. You may try to use a release lib with a debug compilation. You need to check.

    [quote author="mirror3000" date="1374788633"]
    Another problem I get is when I try to include <CL/cl.h>.
    @C1083: Cannot open include file: 'CL/cl.h': No such file or directory.@
    [/quote]

    Where is the include file located?
    Your current project.pro allows only includes from
    @
    INCLUDEPATH += c:/opencl/include
    @

    You need to add the location where the actual include is located.

    Based on this information
    [quote author="mirror3000" date="1374788633"]
    @win32: LIBS += -L$$PWD/../../../../../Program Files/NVIDIA GPU Computing Toolkit/CUDA/v5.0/lib/Win32/ -lOpenCL

    INCLUDEPATH += $$PWD/../../../../../Program Files/NVIDIA GPU Computing Toolkit/CUDA/v5.0/lib/Win32
    DEPENDPATH += $$PWD/../../../../../Program Files/NVIDIA GPU Computing Toolkit/CUDA/v5.0/include

    win32: PRE_TARGETDEPS += $$PWD/../../../../../Program Files/NVIDIA GPU Computing --Toolkit/CUDA/v5.0/lib/Win32/OpenCL.lib@
    [/quote]

    I guess it should be something like
    @
    INCLUDEPATH += c:/opencl/include
    INCLUDEPATH += c:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v5.0/lib/include
    @


  • Lifetime Qt Champion

    Hi,

    to add to what koahnig wrote, IIRC when installing cuda sets up some environment variables containing the path to its installation folder, you can use them in your pro file



  • @SGaist Yes, they do add environment variables. Thanks for the tip:)

    The compiler I use with QtCreator is MSVC 11 x64.
    I tried including both the X64 and Win32 libraries, but it didn't work with debug compilation. It works with release compilation.


  • Lifetime Qt Champion

    What doesn't work in debug mode ?


Log in to reply
 

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