OpenCL 2.x(C++ bindings): undefined identifier - c++

Edit: adding OpenCL.lib in library files section of visual studio solved the problem.
With cl2.hpp from this github repository pointed by khronos site, I get 60-70 similar errors when I try to compile a C++ dll project with OpenCL-C++-implementation functions to export.
'CL_DEVICE_QUEUE_ON_HOST_PROPERTIES': undeclared identifier
// I'm not using this, I'm newly converting a v1.2 C++ binding-based
// project to a v2.0 one
starting of the file is:
using namespace std;
#define __CL_ENABLE_EXCEPTIONS
#include <CL\cl2.hpp>
and the remaining lines are not underlined with red(visual studio). There are some compile time constants I need to add maybe, but I don't know which constants.
What is missing?
this code(there isn't any other code in project) also gives same error:
#include <CL\cl2.hpp>

I had the same errors and something that worked for me was to add the following prior to #include <cl2.hpp>
#define CL_HPP_TARGET_OPENCL_VERSION 120
#define CL_HPP_MINIMUM_OPENCL_VERSION 120
#include <cl2.hpp>

Related

C2014 error when adding stb_image to visual studio project

I am planning on using the library stb_image by Sean Barrett to load images into a graphics application. Lib code at the repository below:
https://github.com/nothings/stb/blob/master/stb_image.h
Though its documentation is short and clear for me in terms of adding the header stb_image.h to your project, and then:
Do this:
#define STB_IMAGE_IMPLEMENTATION
before you include this file in *one* C or C++ file to create the implementation.
// i.e. it should look like this:
#include ...
#include ...
#include ...
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
when I build it on VS2013, the compiler throws the following error:
Error 1 error C2014: preprocessor command must start as first nonwhite space c:\users\ed\desktop\opengl\stbi\stb_image.h 2318 1 STBI
...
At the beginning, I thought it was it was a line ending problem (Win32 LF, Linux CR LF), but it seems not to be.
Any hints of what might be causing this error is welcome !

Using OpenBLAS LAPACKE in Visual Studio

i need some linear algebra in my project and want use OpenBLAS for this. I downloaded the precompiled version (64bit version) and unpacked it to my projectfolder. In Visual Studio, i added include-, bin-, and lib-folder to my Project and ran the this example without problems.
Next, i wanted to look at LAPACK, so i added lapacke.h to the includes, which is in the same directory as cblas.h and is included in the official download. But now i get hundreds of errors, for every function, as if a lib file was missing or something. E.g. for this line
85 lapack_complex_float lapack_make_complex_float( float re, float im );
i get
PATH\include\lapacke.h(85): error C2146: syntax error: missing ';' before identifier 'lapack_make_complex_float'
I can't find any further information on how to set up OpenBLAS/LAPACK, they usually just say 'include the files', which i have. Otherwise the cblas example wouldn't run either. And the (relevant) examples i can find only use cblas.h, not lapacke.h
Can some tell me what i'm doing wrong?
The problem is that OpenBlas uses C99 _Complex by default. This is not supported by Visual C++. You can solve this by using standard library definitions before including lapacke.h:
#include <complex>
#define lapack_complex_float std::complex<float>
#define lapack_complex_double std::complex<double>
#include <lapacke.h>
Using std::complex is problematic unless OpenBLAS was built with LAPACK_COMPLEX_CPP otherwise the library uses a different complex type internally, usually C99 _Complex.
Modern versions of the Microsoft compiler (e.g. the one in VSTUDIO 2022) support a similar "_Complex" mechanism. Therefore I include the following header file prior to "lapacke.h"
#ifdef _MSC_VER
#include <complex.h>
#define LAPACK_COMPLEX_CUSTOM
typedef _Dcomplex lapack_complex_float;
typedef _Fcomplex lapack_complex_double;
#define lapack_complex_float_real(z) (real(z))
#define lapack_complex_float_imag(z) (imag(z))
#endif // _MSC_VER
See the lapack.h header file that ships with OpenBLAS how #define LAPACK_COMPLEX_CUSTOM overrides complex variable type definitions

C++ project build, but IDE shows error

Error: cannot open source file "GL/glew.h"
I have the following code :
//Include GLEW
#include <GL/glew.h>
//Include GLFW
#include <GLFW/glfw3.h>
//Include the standard C++ headers
#include <stdio.h>
#include <stdlib.h>
//Define an error callback
static void error_callback(int error, const char* description)
{
...
I took from there: http://www.41post.com/5178/programming/opengl-configuring-glfw-and-glew-in-visual-cplusplus-express#part4
In order to have a somewhat portable solution, before I even started Visual Studio 2013 I created two System Environment Variable in windows.
GLEW=C:\Install\Development\C++\Framework\glew-1.10.0-win32\glew-1.10.0
GLFW=C:\Install\Development\C++\Framework\glfw-3.0.4.bin.WIN32\glfw-3.0.4.bin.WIN32
So in my project I could for instance write a additional include folder as: %GLEW%\include
As I said, it builds fine and runs fine as well.
Yet, not having intellisense behave properly is really annoying.
How to fix it?
My syntax was actually wrong, you cant use global environment variable in VS using %<name>% but you have to use $(%<name>).
Wherever I wrote %GLEW%\include I should have $(GLEW)\include.
It's working fine now.
Though I'm completely clueless why it built.
This post: https://stackoverflow.com/a/11543754/910813 got me to remind that.

opencv errors while using with windows form applications

I am using opencv with visual studio 2010 windows form application c++. but it wont allow calling inbuilt functions. It gives errors like
Error 1 error C3861: 'cvCvtColor': identifier not found c:\users\ayesha\documents\visual studio 2010\projects\abc\abc\Form1.h 140 1 abc
Error 2 error C3861: 'cvCvtPixToPlane': identifier not found c:\users\ayesha\documents\visual studio 2010\projects\abc\abc\Form1.h 146 1 abc
I have added the following headers
#include "highgui.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
Can anyone please tell me what i am doing wrong.
Unfortunately, OP doesn't say what version of OpenCV he uses.
While working with OpenCV 3.0, use cvSplit() instead of cvCvtPixToPlane().
cvCvtColor() shall work with OpenCV 3.0, provided you added the required header files to your projects.
Finally, to make sure you don't miss any required files in your project, just start your code with #include <opencv2\opencv.hpp>.
cvCvtColor is a C API function of OpenCV, but you're intending to use the C++ one. You have 2 ways of fixing the problem:
1) (Recommended) Change your source code to use the C++ API. You should use cv::Mat instead of CvArr, cv::cvtColor instead of cvCvtColor, etc.
2) Since such changes in the source code can be pretty involved, you can still use the C API by including C-headers
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/core/core_c.h"
#include "opencv2/highgui/highgui_c.h"
instead of the C++ (*.hpp) ones
The error you've mentioned it is a linker error I suppose.
As you're including two headers highgui.hpp and highgui.h targeting to an identical library which is opencv_highgui23#.
Just include only one header.

Boost build error with websocketpp and MySQL on Windows

I am trying to build a C++ app that uses both websocketpp and MySQL. I have encountered 2 build problems using VS 2010 C++ Express.
1) A problem with the boost libraries. It produces many errors like this:
1>c:\program files (x86)\boost\boost_1_50\boost\thread\win32\thread_data.hpp(210): error C2146: syntax error : missing ')' before identifier 'rel_time'
Here's the relevant snippet from thread_data.hpp starting with line 210:
inline BOOST_SYMBOL_VISIBLE void sleep(TimeDuration const& rel_time)
{
interruptible_wait(detail::pin_to_zero(rel_time.total_milliseconds()));
}
2) A conflict with the word VERSION which is documented here and I believe is independent.
To make a clear and simple example of the boost build problems, I'm using the websocketpp example: echo_server.cpp to which I added these includes:
#include "stdafx.h"
Boost lib includes recommended by "Building a program with websocketpp" on the websocketpp site.
#include <boost/regex.hpp>
#include <boost/random.hpp>
#include <boost/system/api_config.hpp>
#include <boost/system/config.hpp>
#include <boost/system/error_code.hpp>
#include <boost/system/system_error.hpp>
#include <boost/system/windows_error.hpp>
and the MySQL header includes. Adding these 2 boostincludes triggers the build errors. If I comment out these 2 includes, it builds without errors:
#include <my_global.h>
#include <mysql.h>
Any suggestions on how to deal with the boost problems?
I don't think this is the same build problem as this one, "Trying to build websocket++ with MinGW: last few linker errors — what could it be?"
Concerning the first error, check if there are any macros interfering with the code. Right-click and go to definition or #define the macro yourself at the beginning of the file and see where it gets redefined. In really hard cases, look at the preprocessor output via a compiler flag.
Concerning the rest, you don't provide any versions for Boost and MySQL. Then, there is my_global.h (or is that part of MySQL?) and stdafx.h, which are both under your control but you don't show them here. Also, try to reduce the issue to the smallest possible piece of code. In short, provide a reproducible example.