[Solved]Compile opencl codes with clang and QtCreator on mac 10.8.3
-
wrote on 25 Mar 2013, 04:11 last edited by
@
#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();
}
@error messages
Undefined symbols for architecture x86_64:
"_clGetDeviceIDs", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64mac 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 = appSOURCES += main.cpp
mainwindow.cppHEADERS += mainwindow.h
FORMS += mainwindow.ui
@
Qt ver : Qt5.0.1
compiler : clang3.2
OS : mac10.8.3 -
wrote on 25 Mar 2013, 04:54 last edited by
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 -
wrote on 29 Jun 2013, 02:19 last edited by
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!
-
wrote on 1 Jul 2013, 13:33 last edited by
[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 -
wrote on 21 Nov 2015, 22:40 last edited by
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 OpenCLYou 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.