Linking Error for clCreateFromGLTexture Only - opencl

I am trying to allow OpenCL to render to 2D textures. I first encountered the function clCreateFromGLTexture2D. I wrote it in, but when I went to compile, I found that it was not defined. I eventually found it in "cl_gl.h":
#ifdef CL_USE_DEPRECATED_OPENCL_1_1_APIS
#warning CL_USE_DEPRECATED_OPENCL_1_1_APIS is defined. These APIs are unsupported and untested in OpenCL 1.2!
extern CL_API_ENTRY cl_mem CL_API_CALL
clCreateFromGLTexture2D(cl_context /* context */,
cl_mem_flags /* flags */,
cl_GLenum /* target */,
cl_GLint /* miplevel */,
cl_GLuint /* texture */,
cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
extern CL_API_ENTRY cl_mem CL_API_CALL
clCreateFromGLTexture3D(cl_context /* context */,
cl_mem_flags /* flags */,
cl_GLenum /* target */,
cl_GLint /* miplevel */,
cl_GLuint /* texture */,
cl_int * /* errcode_ret */) CL_EXT_SUFFIX__VERSION_1_1_DEPRECATED;
#endif /* CL_USE_DEPRECATED_OPENCL_1_2_APIS */
So, I looked elsewhere in "cl_gl.h" and I found clCreateFromGLTexture. In the interest of forward compatibility, I wrote that into the code instead. However, the function clCreateFromGLTexture causes a LNK2019 (unresolved external). I find this very suspect, as I CAN compile when using clCreateFromGLBuffer and clCreateFromGLRenderbuffer, and both of these are ALSO in "cl_gl.h".
So, my question: why doesn't clCreateFromGLTexture have a definition, while the functions right next to it in the same module do? I am currently linking against "OpenCL.lib". Is there anything else I need? I didn't see anything. Is this a problem with the library itself?
[EDIT: clGetDeviceInfo(device_id,CL_DEVICE_IMAGE_SUPPORT,sizeof(cl_bool),&result,NULL); is CL_TRUE, for what it's worth.]
Thanks,

Try updating the OpenCL libraries to the latest version(1.2).
clCreateFromGLTexture is defined as part of the OpenCL 1.2 standard, whereas clCreateFromGLTexture2D and clCreateFromGLTexture3D are part of OpenCL 1.0. If your OpenCL library is not up to date, you will get an undefined error.

Even I got this error and I had some tough time fixing it. I guess you are using VS2010.
This may happen for reasons such as:
you have not included the reference to the library in the project properties -> linker -> input -> Additional Library dependencies
you have compiled the solution as 32bit and using the 64bit library file or vice versa.
Check it out.

Related

cannot convert cont char* to LPCWSTR

I am stuck with an error in QT compiler however it works fine with VS2010. the error states that
I have seen other posts related to the same error but non has resolved my problem in QT. I have tried _T,L or TEXT but still not working
bq. error: C2664: 'HANDLE
LoadImageW(HINSTANCE,LPCWSTR,UINT,int,int,UINT)' : cannot convert
argument 2 from 'const char *' to 'LPCWSTR' Types pointed to are
unrelated; conversion requires reinterpret_cast, C-style cast or
function-style cast
my code is as below
Bitmap::Bitmap(std::string const& file_name) {
bitmap_ = static_cast<HBITMAP>(::LoadImage(0, file_name.c_str(), IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION));
}
please share if you have any idea to resolve this
Qt does not include a compiler. On Windows you're probably either compiling with mingw or Visual C++. Either way, the issue is that you're calling a function that expects a wide character string but you're trying to hand it an 8-bit character string.
For compatibility reasons, Win32 uses a different set of API functions if you have _UNICODE defined. In your case, you do have _UNICODE defined. You can continue using the 8-bit std::string but simply change the method from LoadImage() to LoadImageA(). Or if you don't mind changing your Bitmap class, you could switch from std::string to std::wstring to take advantage of Windows' Unicode features.
But perhaps the larger question is why use Win32 to load bitmaps and std::string if you're using Qt? Qt's QImage class and QString class provide a full-featured, cross-platform strings and image loaders. Like any comprehensive framework, Qt works best if you only use external features on an as-needed basis.
I'm not sure if this method is the best, but I've used them on my projects and it works fine, see:
char *source = "Hello world";
WCHAR target[size];
MultiByteToWideChar(CP_ACP, 0, source, -1, target, size);
LPCWSTR final = target;
MessageBox(0, final, TEXT("title"), 0); //Sample usage

Changing function reference in Mach-o binary

I need to change to reference of a function in a mach-o binary to a custom function defined in my own dylib. The process I am now following is,
Replacing references to older functions to the new one. e.g _fopen to _mopen using sed.
I open the mach-o binary in MachOView to find the address of the entities I want to change. I then manually change the information in the binary using a hex editor.
Is there a way I can automate this process i.e write a program to read the symbols, and dynamic loading info and then change them in the executable. I was looking at the mach-o header files at /usr/include/mach-o but am not entire sure how to use them to get this information. Do there exist any libraries present - C or python which help do the same?
interesting question, I am trying to do something similar to static lib; see if this helps
varrunr - you can easily achieve most if not all of the functionality using DYLD's interposition. You create your own library, and declare your interposing functions, like so
// This is the expected interpose structure
typedef struct interpose_s {
void *new_func;
void *orig_func;
} interpose_t;
static const interpose_t interposing_functions[] \
__attribute__ ((section("__DATA, __interpose"))) = {
{ (void *)my_open, (void *) open }
};
.. and you just implement your open. In the interposing functions all references to the original will work - which makes this ideal for wrappers. And, you can insert your dylib forcefully using DYLD_INSERT_LIBRARIES (same principle as LD_PRELOAD on Linux).

Cannot link Arduino project to include Simulink Code

At work, I recently took training on MATLAB/Simulink, including the Simulink Coder that can generate C code for embedded applications. I wanted to try my hand at it, so I bought an Arduino, and dove in. I am able to write simple sketches with no problem, but have been hitting a brick wall when trying to integrate the code generated by Simulink.
I initially used the Arduino IDE, then Eclipse with the Arduino plug-in, and finally Xcode with the embedXcode templates. (My work machine with Simulink is a PC, but I'm not allowed to install "unauthorized software", so I did the rest on my home Mac.) All three use the same avr-gcc compiler.
All three had the same point of failure: "Undefined Reference" errors on the generated function calls. I believe this to be a linker issue rather than basic syntax or header inclusion, as the Eclipse and Xcode code-completion are working OK, and if I change the call signature in any way, the error changes. I can make references to the data structures OK.
As far as I can tell, the default makefiles are set up to compile and link any files within the folder. A "mass_model2.o" file is being created, at least with Xcode. Finally, if I manually write a separate "myFunction.c" and "MyFunction.h" file with a simple function call, this does compile and run on the device as expected.
In desparation, I copied the entire contents of the generated ".c" file, and pasted them in the main sketch file after my setup() and loop() functions, keeping the same ".h" references, and removed the ".c" file from the project. This actually did compile and run! However, I should not have to touch the generated code in order to use it.
What do I need to do to get this to compile and link properly?
The Simulink code is quite verbose, so here are the key parts:
mass_model2.h excerpts:
#include "rtwtypes.h"
#include "mass_model2_types.h"
/* External inputs (root inport signals with auto storage) */
typedef struct {
int16_T PotPos; /* '<Root>/PotPos' */
} ExternalInputs_mass_model2;
/* External outputs (root outports fed by signals with auto storage) */
typedef struct {
int16_T ServoCmd; /* '<Root>/ServoCmd' */
} ExternalOutputs_mass_model2;
/* External inputs (root inport signals with auto storage) */
extern ExternalInputs_mass_model2 mass_model2_U;
/* External outputs (root outports fed by signals with auto storage) */
extern ExternalOutputs_mass_model2 mass_model2_Y;
/* Model entry point functions */
extern void mass_model2_initialize(void);
extern void mass_model2_step(void);
mass_model2.c excerpts:
#include "mass_model2.h"
#include "mass_model2_private.h"
/* External inputs (root inport signals with auto storage) */
ExternalInputs_mass_model2 mass_model2_U;
/* External outputs (root outports fed by signals with auto storage) */
ExternalOutputs_mass_model2 mass_model2_Y;
/* Model step function */
void mass_model2_step(void)
{
// lots of generated code here
}
/* Model initialize function */
void mass_model2_initialize(void)
{
// generated code here
}
The other referenced headers, "rtwtypes.h" and "mass_model2_private.h" define specific types that are used by the generated code, like int16_T. These files are included in the project, and I do not receive any errors associated with them.
In my sketch file, the setup() function calls mass_model2_initialize(). loop() reads my input (a potentiometer), sets the value in mass_model2_U.PotPos, and calls mass_model2_step(). It then gets mass_model2_Y.ServoCmd and writes the value to a servo for output, and finally has a delay().
You can use this download, http://www.mathworks.com/matlabcentral/fileexchange/24675, with Simulink, Simulink Coder and Embedded Coder. Make sure you have the correct version numbers of each tool.
The #include "Arduino.h" statement is required on the main sketch.

OpengGL glDrawBuffers() in Qt?

is the OpenGL function glDrawBuffers(GLsizei n, const GLenum *bufs) available in Qt?
I'm trying to pass multiple render targets to my fragment shader, QtCreator says the function is not declared in this scope. The idea is to have a frame buffer object with two colorbuffers, and draw with the fragment shader to those two buffers.
FIXED:
Just had to add #define GL_GLEXT_PROTOTYPES 1 to the offending file :(
Qt offers only rudimentary access to OpenGL functions. Loading shaders and textures are amongst them. Render targets are not. Just use a proper extension loader library like GLEW. GLEW will nicely coexist with Qt's functionality.
Derive from QGLWidget and override glInit to call glewInit after calling initializeGL
We just spent some time fixing this. We are running Qt 5.2.1 on OSX 10.8 and Ubuntu 14.04 (sorry no WINDOWS experience) and created an OpenGL3.2 context using QGLFormat.
In OSX there is no problem as all OpenGL3.2 functions (to set uniforms, draw buffers, etc..) are defined in:
#include "OpenGL/gl3.h" ///< already included by Qt.. so nothing to do
On Linux on the other hand, we have to include BOTH of these:
#include "GL/gl.h"
#include "GL/glext.h" ///< not included by Qt!!! manually include it
We also attempted to have our QGLWidget class inherit from QGLFunctions_3_2_Core (this class defines its own copy of glDrawBuffer etc...), but this wasn't useful and simply resulted in a segfault:
Program received signal SIGSEGV, Segmentation fault. 0x0000000000407068
in glGetUniformLocation (this=0xbc5820, name=0x407cd0 "view_projection", program=1)
at /usr/include/qt5/QtGui/qopenglfunctions_3_2_core.h:1075 1075
return d_2_0_Core->GetUniformLocation(program, name);
We also investigated the "#define GL_GLEXT_PROTOTYPES 1" above, but this was only useful when we were using glcorearb.h (you can download this header online).

Determine if an SQLite 3 database is read-only - without using sqlite3_db_readonly()

I need to know whether an SQLite database I opened is read-only. I have to use a slightly outdated version of SQLite, where there is no sqlite3_db_readonly() yet. The implementation of sqlite3_db_readonly() uses private calls, so it cannot be copied to the client code. What can be done, besides checking if the file is writable before opening?
EDIT: the version is 3.7.0.1.
EDIT 2: I am using the amalgamation.
You probably already got your hands on the sqlite3 "Database Connection Handle" object. It is defined in sqliteInt.h:
struct sqlite3 {
sqlite3_vfs *pVfs; /* OS Interface */
int nDb; /* Number of backends currently in use */
Db *aDb; /* All backends */
int flags; /* Miscellaneous flags. See below */
int openFlags; /* Flags passed to sqlite3_vfs.xOpen() */
int errCode; /* Most recent error code (SQLITE_*) */
int errMask; /* & result codes with this before returning */
You can then test for read-only with the openFlags member against O_RDWR.
#define O_RDONLY 00000000
#define O_WRONLY 00000001
#define O_RDWR 00000002
For sure this is not the same as the newer sqlite3_db_readonly(), but it might be enough in your context.
Edit
Following up on your comment you can do the following to "future-proof" your code:
check if the sqlite3 struct varies between 3.7.0.1 and the first version that supports sqlite3_db_readonly()
use some macros to map the right dupe of the sqlite3 struct (or the right offset of openFlags) with the corresponding 3.x.y.z version since SQLITE_VERSION_NUMBER is defined in sqlite3.h.
starting with the version that supports sqlite3_db_readonly() just invoke it.
Note that a database will be opened read-only if its file can only be opened for read, whether the sqlite3_open_v2 function is used with the SQLITE_OPEN_READONLY or not. So in addition to the aforementioned openFlags you'll also need to separately verify if the file can be opened read-only. The C API provides the function xAccess in the sqlite3_vfs struct. I'm guessing that this work whether your application already has a lock on the db file. See http://www.sqlite.org/c3ref/vfs.html for more info.

Resources