Can't get boost's sample main.cpp to compile

197 views
Skip to first unread message

Joshua Laferriere

unread,
Jun 26, 2016, 10:18:18 PM6/26/16
to boost-compute
I posted the issue on stackexchange: http://stackoverflow.com/questions/38045020/boost-compute-opencl-wrapper-initial-setup-problems-qt-g

copied here for reference

Been trying to compile this sample code: https://github.com/boostorg/compute/blob/master/README.md

I installed QT Creator 5.7 using mingw530

I compiled the boost libraries using

bootstrap.bat gcc
b2 install --prefix="C:\Boostbuild" --toolset=gcc
bjam --build-dir=c:/Dev/Boost/Boost_lib toolset=gcc stage

I installed AMD SDK 3.0, 2.9.1, and 2.9

I even downloaded opencl 1.1, 1.2, and 2.1 cl.hpp and tried to include that.

The compile starts, but I get a slew of errors

C:\Dev\Boost\compute-master\include\boost\compute\device.hpp:80: error: undefined reference to `clRetainDevice@4'

C:\Users\User\Documents\Projects\build-console-test-Desktop_Qt_5_7_0_MinGW_32bit-Debug\debug\main.o:-1: In function `ZN5boost7compute6deviceaSERKS1_':

I tried a simple qt console app, using the code supplied by boost compute

Note: this isn't specific to qt, I've also tried compiling this using

g++ -I/path/to/compute/include sort.cpp -lOpenCL

doing an -I to each of the include's in the main.cpp (see below)

Ideally, I'd like to know how to compile the example given on their page, with includes and all (and relevant amd sdk and/or opencl versions) along with the necessary included libraries.

My qt project file libraries

INCLUDEPATH += C:\Dev\Boost\compute-master\include
INCLUDEPATH += C:/Users/User/Downloads/dev/boost_1_61_0
INCLUDEPATH += "C:\Program Files (x86)\AMD APP SDK\2.9-1\include"

My main.cpp

#include <iostream>
#include <vector>
#include <algorithm>
#include <boost/compute.hpp>
//#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
//#undef CL_VERSION_1_2
//#include <C:\Dev\OpenCL\2.1\cl.hpp>

namespace compute = boost::compute;

int main()
{

// get the default compute device
compute::device gpu = compute::system::default_device();

// create a compute context and command queue
compute::context ctx(gpu);
compute::command_queue queue(ctx, gpu);

// generate random numbers on the host
std::vector<float> host_vector(1000000);
std::generate(host_vector.begin(), host_vector.end(), rand);

// create vector on the device
compute::vector<float> device_vector(1000000, ctx);

// copy data to the device
compute::copy(
host_vector.begin(), host_vector.end(), device_vector.begin(), queue
);

// sort data on the device
compute::sort(
device_vector.begin(), device_vector.end(), queue
);

// copy data back to the host
compute::copy(
device_vector.begin(), device_vector.end(), host_vector.begin(), queue
);

return 0;
}

if I uncomment out the include cl.hpp, I get further

C:/Dev/Boost/compute-master/include/boost/compute/allocator/buffer_allocator.hpp:91: undefined reference to `clReleaseMemObject@4'

Kyle Lutz

unread,
Jun 27, 2016, 12:11:09 AM6/27/16
to Joshua Laferriere, boost-compute
Hi Joshua,

It looks like the OpenCL library isn't being properly linked in (which
leads to the "undefined reference to 'cl...'" errors). Also, make sure
that the OpenCL headers you're compiling against match the OpenCL
library version you're linking against (e.g. make sure to use the v1.2
headers with a v1.2 OpenCL library).

To help debug more, can you try this more reduced test case which just
uses OpenCL, no Boost.Compute:

#include <stdio.h>
#include <CL/cl.h>

int main()
{
cl_uint num_platforms = 0;
clGetPlatformIDs(0, 0, &num_platforms);
printf("found %u platforms\n", num_platforms);
return 0;
}

Let me know if that works for you.

-kyle
Message has been deleted

Joshua Laferriere

unread,
Jun 27, 2016, 9:13:33 PM6/27/16
to boost-compute, laferr...@gmail.com
Also, make sure that the OpenCL headers you're compiling against match the OpenCL library version you're linking against (e.g. make sure to use the v1.2 headers with a v1.2 OpenCL library).

how do I verify that?  That is something I've been trying to figure out.  I thought that maybe AMD SDK 3.0 was backwards compatible (in the examples I used, I just happened to keep the DSK at 2.9.1)


Joshua Laferriere

unread,
Jun 27, 2016, 9:16:11 PM6/27/16
to boost-compute, laferr...@gmail.com

To help debug more, can you try this more reduced test case which just
uses OpenCL, no Boost.Compute:

#include <stdio.h>
#include <CL/cl.h>

int main()
{
    cl_uint num_platforms = 0;
    clGetPlatformIDs(0, 0, &num_platforms);
    printf("found %u platforms\n", num_platforms);
    return 0;
}

Let me know if that works for you.

-kyle

project file:
QT += core
QT -= gui

CONFIG += c++11

TARGET = console-test
CONFIG += console
CONFIG -= app_bundle

OPENCL_ROOT = "C:\Program Files (x86)\AMD APP SDK\2.9-1"
isEmpty(OPENCL_ROOT) {
  error("Please set AMDAPPSDKROOT to the location of the AMD APP SDK")
} else {
  message(Using Boost from: $$OPENCL_ROOT)
}

INCLUDEPATH += $$OPENCL_ROOT/include
LIBS += -L$${OPENCL_ROOT}/lib/x86
LIBS += -LOpenCL

INCLUDEPATH += C:\Dev\Boost\compute-master\include
INCLUDEPATH += C:/Users/User/Downloads/dev/boost_1_61_0
INCLUDEPATH += "C:\Program Files (x86)\AMD APP SDK\2.9-1\include"

TEMPLATE = app

SOURCES += main.cpp



C:\Users\User\Documents\Projects\build-console-test-Desktop_Qt_5_7_0_MinGW_32bit-Debug/../console-test/main.cpp:7: undefined reference to `clGetPlatformIDs@12'

collect2.exe: error: ld returned 1 exit status



 

Joshua Laferriere

unread,
Jun 27, 2016, 9:25:53 PM6/27/16
to boost-compute, laferr...@gmail.com
nevermind, figured that cl.hpp is included in the amd sdk, so no need for me to include it.

Joshua Laferriere

unread,
Jun 27, 2016, 9:36:51 PM6/27/16
to boost-compute, laferr...@gmail.com
fixed it:

QT += core QT -= gui
CONFIG += c++11
TARGET = console-test CONFIG += console CONFIG -= app_bundle
OPENCL_ROOT = "C:\Program Files (x86)\AMD APP SDK\2.9-1" isEmpty(OPENCL_ROOT) { error("Please set AMDAPPSDKROOT to the location of the AMD APP SDK") } else { message(Using Boost from: $$OPENCL_ROOT) }
INCLUDEPATH += $$OPENCL_ROOT/include LIBS += -L$${OPENCL_ROOT}/lib/x86
LIBS += -lOpenCL

#INCLUDEPATH += C:\Dev\Boost\compute-master\include #INCLUDEPATH += C:/Users/User/Downloads/dev/boost_1_61_0 #INCLUDEPATH += "C:\Program Files (x86)\AMD APP SDK\2.9-1\include"
Reply all
Reply to author
Forward
0 new messages