[Solved]Compile opencl codes with clang and QtCreator on mac 10.8.3



  • @
    #include "mainwindow.h"
    #include <QApplication>

    #include <OpenCL/cl.h>

    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    cl_uint num_devices, i;
    clGetDeviceIDs(NULL, CL_DEVICE_TYPE_ALL, 0, NULL, &num_devices);
    
    return a.exec&#40;&#41;;
    

    }
    @

    error messages
    Undefined symbols for architecture x86_64:
    "_clGetDeviceIDs", referenced from:
    _main in main.o
    ld: symbol(s) not found for architecture x86_64

    mac is installed with opencl, so I expect this codes should work
    but looks like it can't find the dylib?

    my .pro file
    @
    #-------------------------------------------------

    Project created by QtCreator 2013-03-25T12:04:15

    #-------------------------------------------------

    QT += core gui

    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

    TARGET = openclTest
    TEMPLATE = app

    SOURCES += main.cpp
    mainwindow.cpp

    HEADERS += mainwindow.h

    FORMS += mainwindow.ui

    @

    Qt ver : Qt5.0.1
    compiler : clang3.2
    OS : mac10.8.3



  • looks like this line could solve the problem
    @QMAKE_LFLAGS += -framework OpenCL@

    I am not sure this is a correct solution on mac or not, after
    I confirm this answer is acceptable, I will mark this post as
    Solved



  • This looks like great progress, did you get it to work? FYI, I'm just getting started with Qt and have a big interest in using OpenCL in this fashion. Thanks!



  • [quote author="bruce3141" date="1372472346"]This looks like great progress, did you get it to work? FYI, I'm just getting started with Qt and have a big interest in using OpenCL in this fashion. Thanks![/quote]

    Sorry, I do not notice your reply
    Yes, it work on my mac mini, but the sad thing is the gpu of my mac mini
    do not support opencl yet.

    Just include the header and edit the .pro as I posted
    then you could play opencl on your mac



  • This is my HelloOpenCL *.pro file, it works on Mac.

    TEMPLATE = app
    CONFIG += console c++11
    CONFIG -= app_bundle
    CONFIG -= qt
    SOURCES += main.cpp
    QMAKE_LFLAGS += -framework OpenCL

    You have to install XCode first.
    Mac doesn't include the cl.hpp file. If you want to use C++ for OpenCL, download the header file from Khronos (https://www.khronos.org/registry/cl/api/2.1/cl.hpp), use the OpenCL C header in your program file (#include <OpenCL/opencl.h>), and store cl.hpp file in the same folder as where opencl.h is (find it by placing cursor on opencl.h and pressing F2, then press CMD+SHFT+S to get the file saving dialog which shows the folder you're in).
    The comments in cl.hpp show the code for your first Hello OpenCL program.


Log in to reply
 

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