1
votes

I think this is a simple problem but I can't figure it out. In Visual Studio you add an include directory, a library directory, and a dependency (OpenCL.lib) via the project properties dialog.

But in Qt Creator it lets you add an external library but it doesn't help you set up header files and typing the absolute path to the header file doesn't work. Adding the header file to the .pro file doesn't seem to be working either.

So I add the external library

Add library dialog

And then I try adding the path to the header file in INCLUDEPATH:

INCLUDEPATH += $$PWD/../../../../../../Program Files (x86)/AMD APP/lib/x86    
               $$PWD/../../../../../../Program Files (x86)/AMD APP/include

Screenshot of code

This time the error it gives is:

Screenshot of error

But I have also received:

"Can't open File.obj" // this happens if I just add the External Library and then click build
"No such file or directory 'C:/Program Files (x86)/AMD APP/include/CL/cl.h'" // but that file does exist.

SOLUTION

For anyone that needs it the .pro file that eventually worked is

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = clTest100
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

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

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

2 Answers

5
votes

Problem is simple: spaces! Spaces have spatial meaning they separate values in pro file. You have to surround paths and file names which contains spaces with double quotes!

Another problem is missing tailing back slash meaning that you are continuing adding parameters in next line like Phlucious wrote.

off topic:
Proper approach is to create prf file since every project with openCL will use same settings for it. Also each machine has different location of this library so each machine has to have own version of prf file. In other cases you will have problems with collaboration (sharing code with other developer). If you use prf file then you will include it by adding in your project: CONFIG += <prf file name>

So content of your prf file should look like this:

INCLUDEPATH += "c:/Program Files (x86)/AMD APP/include"
LIBS += -L"c:/Program Files (x86)/AMD APP/lib/x86" -lOpenCL



INCLUDEPATH += "c:/Program Files \(x86\)/AMD APP/include"
LIBS += -L"c:/Program Files \(x86\)/AMD APP/lib/x86" -lOpenCL

and if this doesn't work try escape with triple slashes (I've fond some crapy link with this kind of approach):

INCLUDEPATH += "c:/Program Files \\\(x86\\\)/AMD APP/include"
LIBS += -L"c:/Program Files \\\(x86\\\)/AMD APP/lib/x86" -lOpenCL

Maybe better solution is to instal those libraries into some more convenient directory, which doesn't contain parenthesis and spaces.

You can also try to add to pro file, for debugging purposes something like:

message(LIBS $$LIBS)
message(INCLUDEPATH $$INCLUDEPATH)
1
votes

You need to have a backslash at the end of every line except the last one when you want an expression to split over multiple lines in a PRO file.

For example, your

INCLUDEPATH += $$PWD/../../../../../../Program Files (x86)/AMD APP/lib/x86    
               $$PWD/../../../../../../Program Files (x86)/AMD APP/include

should be

INCLUDEPATH += $$PWD/../../../../../../Program Files (x86)/AMD APP/lib/x86 \
               $$PWD/../../../../../../Program Files (x86)/AMD APP/include