Using ArrayFire and Boost Compute in single code - opencl

I am trying to run a code which uses functions from both boost compute library and arrayfire library. I am getting the following errors when I try to build the code:
Scanning dependencies of target hello
[ 50%] Building CXX object CMakeFiles/hello.dir/hello.cpp.o
In file included from /opt/arrayfire/include/CL/cl.h:32,
from /usr/include/boost/compute/cl.hpp:19,
from /usr/include/boost/compute/system.hpp:20,
from /usr/include/boost/compute/algorithm/accumulate.hpp:17,
from /usr/include/boost/compute/algorithm.hpp:18,
from /usr/include/boost/compute.hpp:14,
from /home/rcms/debruijn/arrayfire/hello.cpp:2:
/opt/arrayfire/include/CL/cl_version.h:34:104: note: #pragma message: cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 220 (OpenCL 2.2)
34 | #pragma message("cl_version.h: CL_TARGET_OPENCL_VERSION is not defined. Defaulting to 220 (OpenCL 2.2)")
| ^
[100%] Linking CXX executable hello
/usr/bin/ld: CMakeFiles/hello.dir/hello.cpp.o: undefined reference to symbol 'clGetDeviceIDs##OPENCL_1.0'
/usr/bin/ld: /opt/arrayfire/lib64/libOpenCL.so.1: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/hello.dir/build.make:85: hello] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/hello.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
The code I am using is a very simple helloworld using functions from both libraries.
#include <iostream>
#include <boost/compute.hpp>
#include <arrayfire.h>
namespace compute = boost::compute;
using namespace af;
int main()
{
// Boost Compute Part
// get the default device
compute::device device = compute::system::default_device();
// print the device's name and platform
std::cout << "hello from " << device.name();
std::cout << " (platform: " << device.platform().name() << ")" << std::endl;
// Array Fire Part
std::cout<< "ArrayFire Part:" << std::endl;
af::setDevice(0);
af::info();
return 0;
}
The CMakeList used to build the project is:
cmake_minimum_required(VERSION 3.0)
project(deBruijn_Graph)
find_package(ArrayFire)
add_executable(hello hello.cpp)
target_link_libraries(hello ArrayFire::afopencl)
I do not have a programming background. Please guide me on what I am doing wrong. How can I link these two libraries together in a single code?
Regards,
Hassan

Related

Header sqlite3.h does not work in a c program

I am trying to use the sqlite library in a main.c file:
#include <stdio.h>
#include "sqlite3.h"
int main() {
printf("%s\n", sqlite3_libversion());
return 0;
}
But I get the following error:
CMakeFiles\Database.dir/objects.a(main.c.obj): In function `main':
C:/Users/Andrea/Desktop/Database/main.c:7: undefined reference to `sqlite3_libversion'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [CMakeFiles\Database.dir\build.make:104: Database.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles\Makefile2:94: CMakeFiles/Database.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:101: CMakeFiles/Database.dir/rule] Error 2
mingw32-make.exe: *** [Makefile:136: Database] Error 2
I downloaded the sqlite3.h file from the official website and put it in the same folder of the main.c file.
Here is the CMakeList.txt:
cmake_minimum_required(VERSION 3.19)
project(Database C)
set(CMAKE_C_STANDARD 11)
add_executable(Database main.c sqlite3.h)
Please, can you help me modify the CMakeList.txt file so that the code can be compiled?

Kaaproject esp8266 build conflicting types

I have installed the ESP8266 SDK and toolchain and try to build the project CDataCollectionDemo which is generated from kaa sandbox. And I get the error like this
/opt/Espressif/esp-rtos-sdk/include/espressif/c_types.h:47:29: error: conflicting types for ‘size_t’
typedef unsigned int size_t;
^
In file included from /opt/Espressif/esp-rtos-sdk/extra_include/string.h:14:0,
from /home/tung/kaa/project/CDataCollectionDemo/targets/esp8266/target.
here is the full output
tung#ubuntu:~/kaa/project/CDataCollectionDemo$ sudo ./build.sh deploy
-- The C compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
==================================
BUILD_TYPE = (Default)
KAA_PLATFORM = posix
KAA_MAX_LOG_LEVEL = 3
==================================
BOOTSTRAP ENABLED
PROFILE ENABLED
USER EXTENSION ENABLED
CONFIGURATION ENABLED
EVENTS ENABLED
LOGGING ENABLED
NOTIFICATION ENABLED
ENCRYPTION ENABLED
KAA WILL BE INSTALLED TO /usr/local
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE)
-- Could NOT find cppcheck
-- WiFi AP: WiFi SSID
-- WiFi Pass:
-- Configuring done
-- Generating done
-- Build files have been written to: /home/tung/kaa/project/CDataCollectionDemo/build
Scanning dependencies of target target_support
[ 1%] Building C object targets/esp8266/CMakeFiles/target_support.dir/target.c.o
In file included from /opt/Espressif/esp-rtos-sdk/extra_include/sys/config.h:4:0,
from /opt/Espressif/esp-rtos-sdk/extra_include/_ansi.h:16,
from /opt/Espressif/esp-rtos-sdk/extra_include/string.h:10,
from /home/tung/kaa/project/CDataCollectionDemo/targets/esp8266/target.c:17:
/opt/Espressif/esp-rtos-sdk/extra_include/machine/ieeefp.h:277:2: error: #error Endianess not declared!!
#error Endianess not declared!!
^
In file included from /opt/Espressif/esp-rtos-sdk/include/espressif/esp_common.h:9:0,
from /opt/Espressif/esp-rtos-sdk/include/freertos/portmacro.h:73,
from /opt/Espressif/esp-rtos-sdk/include/freertos/portable.h:318,
from /opt/Espressif/esp-rtos-sdk/include/freertos/FreeRTOS.h:87,
from /home/tung/kaa/project/CDataCollectionDemo/targets/esp8266/target.c:19:
/opt/Espressif/esp-rtos-sdk/include/espressif/c_types.h:47:29: error: conflicting types for ‘size_t’
typedef unsigned int size_t;
^
In file included from /opt/Espressif/esp-rtos-sdk/extra_include/string.h:14:0,
from /home/tung/kaa/project/CDataCollectionDemo/targets/esp8266/target.c:17:
/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h:212:23: note: previous declaration of ‘size_t’ was here
typedef __SIZE_TYPE__ size_t;
^
In file included from /opt/Espressif/esp-rtos-sdk/include/espressif/esp_common.h:10:0,
from /opt/Espressif/esp-rtos-sdk/include/freertos/portmacro.h:73,
from /opt/Espressif/esp-rtos-sdk/include/freertos/portable.h:318,
from /opt/Espressif/esp-rtos-sdk/include/freertos/FreeRTOS.h:87,
from /home/tung/kaa/project/CDataCollectionDemo/targets/esp8266/target.c:19:
/opt/Espressif/esp-rtos-sdk/include/espressif/esp_libc.h:10:7: error: conflicting types for ‘strncpy’
char *strncpy(char *dst, const char *src, size_t n);
^
/opt/Espressif/esp-rtos-sdk/include/espressif/esp_libc.h:12:5: error: conflicting types for ‘strncmp’
int strncmp(const char *s1, const char *s2, size_t n);
^
/opt/Espressif/esp-rtos-sdk/include/espressif/esp_libc.h:13:8: error: conflicting types for ‘strlen’
size_t strlen(const char *s);
^
/opt/Espressif/esp-rtos-sdk/include/espressif/esp_libc.h:16:7: error: conflicting types for ‘strncat’
char *strncat(char *dst, const char *src, size_t count);
^
/opt/Espressif/esp-rtos-sdk/include/espressif/esp_libc.h:17:8: error: conflicting types for ‘strspn’
size_t strspn(const char *s, const char *accept);
^
/opt/Espressif/esp-rtos-sdk/include/espressif/esp_libc.h:18:8: error: conflicting types for ‘strcspn’
size_t strcspn(const char *s, const char *reject);
^
/opt/Espressif/esp-rtos-sdk/include/espressif/esp_libc.h:26:6: error: conflicting types for ‘bzero’
void bzero(void *s, size_t n);
^
/opt/Espressif/esp-rtos-sdk/include/espressif/esp_libc.h:28:7: error: conflicting types for ‘memcpy’
void *memcpy(void *dst, const void *src, size_t n);
^
/opt/Espressif/esp-rtos-sdk/include/espressif/esp_libc.h:29:7: error: conflicting types for ‘memset’
void *memset(void *dst, int c, size_t n);
^
/opt/Espressif/esp-rtos-sdk/include/espressif/esp_libc.h:30:5: error: conflicting types for ‘memcmp’
int memcmp(const void *m1, const void *m2, size_t n);
^
/opt/Espressif/esp-rtos-sdk/include/espressif/esp_libc.h:31:7: error: conflicting types for ‘memmove’
void *memmove(void *dst, const void *src, size_t n);
^
/opt/Espressif/esp-rtos-sdk/include/espressif/esp_libc.h:37:5: warning: conflicting types for built-in function ‘snprintf’ [enabled by default]
int snprintf(char *buf, unsigned int count, const char *format, ...);
^
/opt/Espressif/esp-rtos-sdk/include/espressif/esp_libc.h:41:7: warning: conflicting types for built-in function ‘malloc’ [enabled by default]
void *malloc(size_t n);
^
/opt/Espressif/esp-rtos-sdk/include/espressif/esp_libc.h:43:7: warning: conflicting types for built-in function ‘calloc’ [enabled by default]
void *calloc(size_t c, size_t n);
^
/opt/Espressif/esp-rtos-sdk/include/espressif/esp_libc.h:45:7: warning: conflicting types for built-in function ‘realloc’ [enabled by default]
void *realloc(void *p, size_t n);
^
make[2]: *** [targets/esp8266/CMakeFiles/target_support.dir/target.c.o] Error 1
make[1]: *** [targets/esp8266/CMakeFiles/target_support.dir/all] Error 2
make: *** [all] Error 2
./build.sh: 52: ./build.sh: ./demo_client: not found
Everything I did follow the kaa documentation, except adding the -DKAA_PLATFORM=esp8266 argument to cmake command in build.sh file. Can you tell me what's problem here and how to fix it. Thank you!
Update
I have added some arguments to cmake command as #MrKoin suggested but still get an error
Cmake arguments
cmake .. \
-DCMAKE_TOOLCHAIN_FILE=../libs/kaa/toolchains/esp8266.cmake \
-DKAA_PLATFORM=esp8266 \
-DCMAKE_BUILD_TYPE=MinSizeRel \
Output
In file included from /home/tung/kaa/project/CDataCollectionDemo/libs/kaa/thirdparty/mbedtls/aes.c:27:0:
/opt/Espressif/crosstool-NG/builds/xtensa-lx106-elf/lib/gcc/xtensa-lx106-elf/4.8.2/include/stdint.h:9:26: fatal error: stdint.h: No such file or directory
# include_next <stdint.h>
^
compilation terminated.
make[2]: *** [libs/kaa/tools/kaa_encryption/rsa_key_gen/mbedtls/CMakeFiles/mbedtls.dir/aes.c.obj] Error 1
make[1]: *** [libs/kaa/tools/kaa_encryption/rsa_key_gen/mbedtls/CMakeFiles/mbedtls.dir/all] Error 2
make: *** [all] Error 2
It seems like some libraries missing. What should I do now? Thanks!
Looks like you need to specify cmake toolchain file in cmake arguments:
cmake -DCMAKE_TOOLCHAIN_FILE=../libs/kaa/toolchains/esp8266.cmake \
-DKAA_PLATFORM=esp8266 ..
Please, refer documentation for details.
It might be related to step 5 Install ESP8266 RTOS SDK in the tutorial you referenced from the Kaa website.
Did you run the command sed -i 's:#include "c_types.h"://#include "c_types.h":' $ESP_SDK_HOME/include/lwip/arch/cc.h?
I remember I had a similar (or the same) problem and forgot to execute this command. It comments out an #include which conflicts with the declaration of types elsewhere.
You need to edit the build.sh file,
find build() and change the code:
build() {
mkdir -p "$PROJECT_HOME/build"
cd "$PROJECT_HOME/build"
cmake ..\
-DKAA_TARGET=esp8266\
-DCMAKE_TOOLCHAIN_FILE=../libs/kaa/toolchains/esp8266.cmake \
-DBUILD_TESTING=OFF \
-DKAA_PLATFORM=esp8266 \
-DBUILD_TESTING=OFF \
-DCMAKE_BUILD_TYPE=MinSizeRel
make
}

Programm crashes using Taglib

I am trying to use Taglib with Qt5.7. But my programm crashes:
The GDB process terminated unexpectedly (exit code 0).
Cannot continue debugged process: The program is not being run.
During startup program exited with code 0xc0000135
There did not seem to be any error messages while building Taglib.
*.pro file
QT += core
QT -= gui
CONFIG += c++11
TARGET = untitled2
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
TAGLIBDIR = $$quote(D:/D/Programmieren/Libraries/taglib)
INCLUDEPATH += $$quote( $${TAGLIBDIR}/include )
LIBS += -L$$quote($${TAGLIBDIR}/lib) -ltag
main.cpp
#include <QCoreApplication>
#include <taglib/tag.h>
#include <taglib/fileref.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
TagLib::FileRef ref("D:/D/Media/Musik/Disturbed/The Sickness/Disturbed - Stupify.mp3");
return a.exec();
}
Edit:
I created Taglib-buildfiles using CMake-GUI and native MinGW-Installation since I did not manage to create them using Qt. My OS is Windows 10 x64 Education and I use Qt-Creator. I downloaded the latest Taglib-Release (1.11.1)
Why I cant create buildfiles using CMake:
First some *dll-files where missing, i coud solve that by just copying the ones from native MinGW-Installation to QT-MinGW.
Second I could not find any of the *exe-files desired by CMake so i could not change the path from native MinGW-Installation.
After rebuilding Taglib in debugmode I get this errors:
main.cpp:10: error: undefined reference to `_imp___ZN6TagLib8FileNameC1EPKc'
main.cpp:10: error: undefined reference to `_imp___ZN6TagLib7FileRefC1ENS_8FileNameEbNS_15AudioProperties9ReadStyleE'
main.cpp:11: error: undefined reference to `_imp___ZNK6TagLib7FileRef3tagEv'
main.cpp:11: error: undefined reference to `_imp___ZNK6TagLib6String9toCStringEb'
main.cpp:11: error: undefined reference to `_imp___ZN6TagLib6StringD1Ev'
main.cpp:10: error: undefined reference to `_imp___ZN6TagLib7FileRefD1Ev'
main.cpp:11: error: undefined reference to `_imp___ZN6TagLib6StringD1Ev'
main.cpp:10: error: undefined reference to `_imp___ZN6TagLib7FileRefD1Ev'
collect2.exe:-1: error: error: ld returned 1 exit status
Solved it by using new version (5.8 instead of 5.7) of Qt.

Compiling Qt 5.3.0 for static linking under windows

I am trying to compile Qt for static linking following this tutorial: http://qt-project.org/wiki/How-to-build-a-static-Qt-for-Windows-MinGW
But i receive tons of warnings and a few errors.
For example this one:
C:/Developement/Qt/Tools/mingw482_32/bin/../lib/gcc/i686-w64-mingw32/4.8.2/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lqjp2
collect2.exe: error: ld returned 1 exit status
Makefile.Release:79: recipe for target '..\..\bin\dumpdoc.exe' failed
mingw32-make[4]: *** [..\..\bin\dumpdoc.exe] Error 1
mingw32-make[4]: Target 'first' not remade because of errors.
mingw32-make[4]: Leaving directory 'C:/Developement/Qt/Static/src/qt-everywhere-opensource-src-5.3.0/qtactiveqt/tools/dumpdoc'
Makefile:34: recipe for target 'release' failed
mingw32-make[3]: *** [release] Error 2
mingw32-make[3]: Target 'first' not remade because of errors.
for this, i set the environement variable to my path:
Name: LIBRARY_PATH
Value: C:\Developement\Qt\5.3\mingw482_32\bin
... but dunno yet if its gonna workin'
Beside this, i put the following paths to the PATH environement variable:
C:\Developement\Qt\5.3\mingw482_32\bin;
C:\Developement\Qt\Tools\mingw482_32\bin;
I am receiving tons of these kind of warning:
In file included from
C:\Developement\Qt\Static\src\qt-everywhere-opensource-src-5.3.0\qtbase\src\3rdparty\libjpeg/jpeglib.h:25:0,
from ......\3rdparty\jasper\src\libjasper\jpg\jpg_jpeglib.h:74,
from ......\3rdparty\jasper\src\libjasper\jpg\jpg_dec.c:75:
C:\Developement\Qt\Static\src\qt-everywhere-opensource-src-5.3.0\qtbase\src\3rdparty\libjpeg/jconfig.h:55:0:
warning: "HAVE_STDDEF_H" redefined [enabled by default] #define
HAVE_STDDEF_H ^ In file included from
......\3rdparty\jasper\src\libjasper\include/jasper/jas_tvp.h:75:0,
from ......\3rdparty\jasper\src\libjasper\jpg\jpg_dec.c:70:
......\3rdparty\jasper\src\libjasper\include/jasper/jas_config.h:65:0:
note: this is the location of the previous definition #define
HAVE_STDDEF_H 1 ^ In file included from
C:\Developement\Qt\Static\src\qt-everywhere-opensource-src-5.3.0\qtbase\src\3rdparty\libjpeg/jpeglib.h:25:0,
from ......\3rdparty\jasper\src\libjasper\jpg\jpg_jpeglib.h:74,
from ......\3rdparty\jasper\src\libjasper\jpg\jpg_dec.c:75:
C:\Developement\Qt\Static\src\qt-everywhere-opensource-src-5.3.0\qtbase\src\3rdparty\libjpeg/jconfig.h:59:0:
warning: "HAVE_STDLIB_H" redefined [enabled by default] #define
HAVE_STDLIB_H ^
In file included from ......\3rdparty\jasper\src\libjasper\include/jasper/jas_tvp.h:75:0,
from ......\3rdparty\jasper\src\libjasper\jpg\jpg_dec.c:70:
......\3rdparty\jasper\src\libjasper\include/jasper/jas_config.h:71:0:
note: this is the location of the previous definition
#define HAVE_STDLIB_H 1
^
......\3rdparty\jasper\src\libjasper\jpg\jpg_dec.c: In function 'jpg_decode':
......\3rdparty\jasper\src\libjasper\jpg\jpg_dec.c:134:49: warning: parameter 'optstr' set but not used
[-Wunused-but-set-parameter]
jas_image_t *jpg_decode(jas_stream_t *in, char *optstr)
^
......\3rdparty\jasper\src\libjasper\jpg\jpg_dec.c: In function 'jpg_start_output':
......\3rdparty\jasper\src\libjasper\jpg\jpg_dec.c:298:47: warning: parameter 'cinfo' set but not used
[-Wunused-but-set-parameter]
static void jpg_start_output(j_decompress_ptr cinfo, jpg_dest_t *dinfo)
^
......\3rdparty\jasper\src\libjasper\jpg\jpg_dec.c: In function 'jpg_finish_output':
......\3rdparty\jasper\src\libjasper\jpg\jpg_dec.c:335:48: warning: parameter 'cinfo' set but not used
[-Wunused-but-set-parameter]
static void jpg_finish_output(j_decompress_ptr cinfo, jpg_dest_t *dinfo)
^ ......\3rdparty\jasper\src\libjasper\jpg\jpg_dec.c:335:67: warning:
parameter 'dinfo' set but not used [-Wunused-but-set-parameter]
static void jpg_finish_output(j_decompress_ptr cinfo, jpg_dest_t *dinfo)
^
Wasn't i prepared enough to compile Qt?
What do i need to do in order to be able to compile Qt without getting errors everytime thrown out?
How long would it take until its compiled.

OpenCV 2.4.6 with QT 5.1.0 Errors

I am trying to get OpenCv2.4.6 to work with QT5.1.0
I've followed this Guide so far Qt creator 5.0.1 with OpenCv 2.3.4 on windows
Unfortunatly after finishing trying out the sample Application(Display an Image using OpenCv in the QtCreator I get these Errors:
[Project-Path]\main.o:-1: In function `main':
[Project-Path]\main.cpp:8: error: undefined reference to `cv::imread(std::string const&, int)'
[Project-Path]\main.cpp:9: error: undefined reference to `cv::namedWindow(std::string const&, int)'
[Project-Path]\main.cpp:10: error: undefined reference to `cv::_InputArray::_InputArray(cv::Mat const&)'
[Project-Path]\main.cpp:10: error: undefined reference to `cv::imshow(std::string const&, cv::_InputArray const&)'
[Project-Path]\main.cpp:11: error: undefined reference to `cv::waitKey(int)'
[Project Build Path Desktop Debug]\debug\main.o:-1: In function `ZN2cv3MatD1Ev':
[OpenCV/Install/include]\opencv2\core\mat.hpp:278: error: undefined reference to `cv::fastFree(void*)'
[Project Build Path Desktop Debug]\debug\main.o:-1: In function `ZN2cv3Mat7releaseEv':
[OpenCV/Install/include]\opencv2\core\mat.hpp:367: error: undefined reference to `cv::Mat::deallocate()'
collect2.exe:-1: error: error: ld returned 1 exit status
the "[]" Paths are my formatting and supposed to help keep track .
main.cpp
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main() {
// read an image
Mat image = imread("img.jpg");
namedWindow("My Image");
imshow("My Image", image);
waitKey(5000);
return 1;
}
myFirstOpenCVProject.pro
QT += core
QT -= gui
TARGET = myFirstOpenCVProject
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:/qt/OpenCV246_bin/install/include
LIBS += -LC:/qt/OpenCV246_bin/install/lib/lopencv_core246.dll
LIBS += -LC:/qt/OpenCV246_bin/install/lib/lopencv_highgui246.dll
LIBS += -LC:/qt/OpenCV246_bin/install/lib/lopencv_imgproc246.dll
LIBS += -LC:/qt/OpenCV246_bin/install/lib/lopencv_features2d246.dll
LIBS += -LC:/qt/OpenCV246_bin/install/lib/lopencv_calib3d246.dll
Can you help me resolve this?
I can't find any solutions that apply to my case ...
-L is to add directories to the search path. The actual libs are added via -l. The correct line would be:
LIBS += -LC:/qt/OpenCV246_bin/install/lib -llopencv_core246 -llopencv_highgui246 ...
I think you are missing the static libs of opencv:
opencv_core246.lib
opencv_highgui246.lib
opencv_video246.lib
opencv_ml26d.lib
opencv_legacy246.lib
opencv_imgproc246.lib
opencv_whatever.lib
Don t know the pro commands very well. Maybe something like:
LIBS += -Lc:/blabla/opencv_imgproc246.lib

Resources