'cdecl attribute ignored error' and how to solve this error? - cdecl

i'm using gcc on ubuntu 20.04 ,gcc version 9.4.0
i use opensources which is 'xsens-old' and then i typed cmake..
and then i got below error result
how to solve this problem?? what does that mean 'attribute ignore' in this situations?
'error result'
cmtdef.h:1134:114: error: ‘cdecl’ attribute ignored [-Werror=attributes]
1134 | instance, int32_t callbackType, void* param, void* userParam);
'code'
typedef void (__cdecl * CmtCallbackFunction)(int32_t instance, int32_t callbackType, void* param, void* userParam);

Related

db2 external function ends with SQL0444N, Reason code 6, SQLSTATE 42724

I'll develop new (external) functions for DB2. My first test:
db2crypt.h
#ifndef DB2CRYPT_H
#define DB2CRYPT_H
#include <string.h>
#include <stdlib.h>
char *encryptAes(const char *source, const char *key);
#endif /* DB2CRYPT_H */
db2crypt.cpp
#include "db2crypt.h"
#include <string>
char *encryptAes(const char *source, const char *key) {
std::string test("abc");
return (char *)test.c_str();
}
is compiled without an error.
g++ -fPIC -c db2crypt.cpp -std=c++14
g++ -shared -o db2crypt db2crypt.o -L$DB2PATH -ldb2
I also copied the new file into $DB2PATH/function and made a softlink in $DB2PATH/function/unfenced.
Then I created the function with
create function aes(VARCHAR(4096), VARCHAR(4096))
SPECIFIC encryptAes
RETURNS VARCHAR(4069)
NOT FENCED
DETERMINISTIC
NO SQL
NO EXTERNAL ACTION
LANGUAGE C
RETURNS NULL ON NULL
INPUT PARAMETER STYLE SQL
EXTERNAL NAME "db2crypt!encryptAes"
which was also ok.
But when I do select db2inst1.aes('a', 'b') from SYSIBM.SYSDUMMY1
I get the error
SQL0444N Die Routine "DB2INST1.AES" (spezifischer Name "ENCRYPTAES") ist
durch Code in Bibliothek oder Pfad ".../sqllib/function/db2crypt", Funktion
"encryptAes" implementiert, auf die kein Zugriff möglich ist. Ursachencode:
"6". SQLSTATE=42724
(sorry, I don't know how to change the error output into english)
What I made wrong?
Ok, I got the answer.
Thank you at #mao, you did help me. But I also needed some other help. If someone searches for an answer:
First you have to compile with some important parameters:
g++ -m64 -fPIC -c <yourfile>.cpp -std=c++14 -I/opt/ibm/db2/V11.1/include/ -D_REENTRANT
g++ -m64 -shared -o <yourfile> <yourfile>.o -L$DB2PATH -ldb2 -Wl,-rpath,$DB2PATH/$LIB -lpthread
Second: The function declaration, you also have to add parameters for null values AND the return value can't be a function return, it has to be a parameter. Also you have to use the types which are defined in sqludf.h:
void SQL_API_FN encryptAes(SQLUDF_CHAR *source,
SQLUDF_CHAR *key,
SQLUDF_CHAR out[4096],
SQLUDF_SMALLINT *sourcenull,
SQLUDF_SMALLINT *keynull,
SQLUDF_SMALLINT *outnull,
SQLUDF_TRAIL_ARGS) {
...
}
Also, when you do C++ instead of C, you have to tell the script that it has to handle the function as C:
#ifdef __cplusplus
extern "C"
#endif
void SQL_API_FN ...

error while compiling with matlab mex

I am try to compile using matlab mex, but i keep receiving this error:
Warning: You are using gcc version "5.4.0-6ubuntu1~16.04.1)". The version
currently supported with MEX is "4.2.3".
For a list of currently supported compilers see:
http://www.mathworks.com/support/compilers/current_release/
In file included from descriptor.h:4:0,
from calc_shot.cpp:11:
mesh.h: In function ‘double magnitude(const vec3d<T>&)’:
mesh.h:106:9: error: ‘sqrt’ is not a member of ‘std’
return std::sqrt((v1.x*v1.x) + (v1.y*v1.y) + (v1.z*v1.z));
^
In file included from calc_shot.cpp:11:0:
descriptor.h: At global scope:
descriptor.h:7:57: error: expected class-name before ‘{’ token
class invalid_mesh_descriptor : public std::logic_error {
^
descriptor.h: In constructor ‘invalid_mesh_descriptor::invalid_mesh_descriptor()’:
descriptor.h:9:57: error: expected class-name before ‘(’ token
explicit invalid_mesh_descriptor() : std::logic_error("Exception invalid_mesh_descriptor caught.") {}
^
descriptor.h:9:57: error: expected ‘{’ before ‘(’ token
descriptor.h: In constructor ‘invalid_mesh_descriptor::invalid_mesh_descriptor(const string&)’:
descriptor.h:10:70: error: expected class-name before ‘(’ token
invalid_mesh_descriptor(const std::string& msg) : std::logic_error("Exception invalid_mesh_descriptor caught: "+msg) {}
^
descriptor.h:10:70: error: expected ‘{’ before ‘(’ token
descriptor.h: In function ‘std::ostream& operator<<(std::ostream&, const vec_descriptor<T>&)’:
descriptor.h:123:45: error: no match for ‘operator<<’ (operand types are ‘std::ostream {aka std::basic_ostream<char>}’ and ‘const char [2]’)
for (size_t k=1; k < d.size(); ++k) s << " " << d(k);
^
In file included from /usr/include/c++/5/string:52:0,
from descriptor.h:5,
from calc_shot.cpp:11:
/usr/include/c++/5/bits/basic_string.h:5172:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
operator<<(basic_ostream<_CharT, _Traits>& __os,
^
/usr/include/c++/5/bits/basic_string.h:5172:5: note: template argument deduction/substitution failed:
In file included from calc_shot.cpp:11:0:
descriptor.h:123:48: note: mismatched types ‘const std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘const char [2]’
for (size_t k=1; k < d.size(); ++k) s << " " << d(k);
^
mex: compile of ' "calc_shot.cpp"' failed.
i used to compile this code with LD_PRELOAD but at the moment i do not remember the argument, how can i solve?
solution:
mex -v calc_shot.cpp shot_descriptor.cpp -DUSE_FLANN -I"C:\Program Files\flann\include" -I/usr/include/eigen3
using this command the programs works like a charm

Why am I getting a "ScriptC sym lookup failed" error?

I am trying to implement a simple luminance histogram in RenderScript using the
atomic arithmetic function rsAtomicInc,
but I get a runtime error which seems to say that function does not exist:
ScriptC sym lookup failed for _Z11rsAtomicIncPVj.
(To verify that this is the correct symbol, you can use:
$ echo "unsigned int __attribute__((overloadable))
rsAtomicInc ( volatile unsigned int *addr ) { return 0; }" > rsai.c
$ clang -c rsai.c; nm rsai.o
dumpbin can be substituted for nm on
Windows.) I have tried using the other atomic functions, which yield similar errors. I get the errors regardless of whether I use them in a kernel or an invokable function.
// histogram.rs:
#pragma version(1)
#pragma rs java_package_name(com.example.android.rs.hellocompute)
#pragma rs_fp_imprecise //relax math- allows NEON and other optimizations
const static float3 gMonoMult = {0.299f, 0.587f, 0.114f};
volatile uint32_t *luminanceHistogram;
void luminance(const uchar4 *img, const void *usrData, uint32_t x, uint32_t y) {
float4 f4 = rsUnpackColor8888(*img);
float3 mono = dot(f4.rgb, gMonoMult);
uchar lum = rsPackColorTo8888(mono).r;
rsAtomicInc(luminanceHistogram + lum);
}
void increment(int lum) {
rsAtomicInc(luminanceHistogram + lum);
}
// HelloCompute.java
int[] luminance = new int[256];
Allocation luminanceHistogram = Allocation.createSized(mRS,
Element.U32(mRS), luminance.length);
ScriptC_histogram histo = new ScriptC_histogram(mRS); // ERROR
Error log:
E/bcc ( 3539): Invalid RS info file /data/data/com.example.android.rs.hellocompute/cache/com.android.renderscript.cache/histogram.o.info! (No such file or directory)
E/RenderScript( 3539): ScriptC sym lookup failed for _Z11rsAtomicIncPVj
E/bcc ( 3539): Some symbols are found to be undefined during relocation!
E/bcc ( 3539): Error occurred when performs relocation on /data/data/com.example.android.rs.hellocompute/cache/com.android.renderscript.cache/histogram.o!
E/RenderScript( 3539): bcc: FAILS to prepare executable for 'histogram'
D/AndroidRuntime( 3539): Shutting down VM
W/dalvikvm( 3539): threadid=1: thread exiting with uncaught exception (group=0x415c6700)
E/AndroidRuntime( 3539): FATAL EXCEPTION: main
E/AndroidRuntime( 3539): android.renderscript.RSRuntimeException: Loading of ScriptC script failed.
E/AndroidRuntime( 3539): at android.renderscript.ScriptC.<init>(ScriptC.java:60)
...
The first error concerning histogram.o.info is probably spurious- a complete uninstall of the app makes it (but none of the other errors) go away for the first run.
This looks like a bug on our part (Android RenderScript team). It looks like those functions just don't exist in our implemented runtime library (even though they exist in the header). I will file a bug internally and get this cleaned up for future releases.

why am i getting these syntax errors when trying to implement system call

still working on this system call!!!
i have added a system call to a kernel, compiled and the OS is running off it.
now i am getting syntax error on the compilation of my test application.
testmycall.h
#include<linux/unistd.h>
#define __NR_mycall 244
_syscall1(long, mycall, int, i)
testmycall.c
#include<stdio.h>
#include "testmycall.h"
int main(int argc, char *argv[])
{
printf("%d\n", mycall(15));
}
here is the error
stef#ubuntu:~$ gcc -o testmycall testmycall.c
In file included from testmycall.c:3:
testmycall.h:7: error: expected ‘)’ before ‘mycall’
stef#ubuntu:~$ gcc -o testmycall testmycall.c
In file included from testmycall.c:3:
testmycall.h:7: error: expected declaration specifiers or ‘...’ before ‘mycall’
testmycall.h:7: error: expected declaration specifiers or ‘...’ before ‘i’
testmycall.c: In function ‘_syscall1’:
testmycall.c:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
testmycall.h:7: error: parameter name omitted
testmycall.h:7: error: parameter name omitted
testmycall.c:11: error: expected ‘{’ at end of input
stef#ubuntu
i have added in the syscall instead of _syscall1
now i get this error
stef#ubuntu:~$ gcc -o testmycall testmycall.c
testmycall.c: In function ‘syscall’:
testmycall.c:7: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
testmycall.c:11: error: expected ‘{’
this is the app, any ideas why???
I believe the _syscallN() macros were removed from the kernel headers around 2.6.18 or so.
The (not especially helpful) error messages from gcc are due to _syscall1 not being defined at all - you get the same errors if you write:
any_old_rubbish_here(long, mycall, int, i)
The syscall() function should work. man syscall for details.
The _syscall macros are obsolete and should not be used, instead use syscall, eg.
#define _GNU_SOURCE
#include <unistd.h>
...
printf("%d\n", syscall(__NR_mycall, 15));
Here's my test program:
#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#define __NR_mycall 244
int main(int argc, char **argv)
{
printf("%d\n", syscall(__NR_mycall,15));
return 0;
}

g++ problem with -l option and PostgreSQL

I've written simple program.
Here a code:
#include <iostream>
#include <stdio.h>
#include <D:\Program Files\PostgreSQL\8.4\include\libpq-fe.h>
#include <string>
using namespace std;
int main()
{
PGconn *conn;
PGresult *res;
int rec_count;
int row;
int col;
cout << "ble ble: " << 8 << endl;
conn = PQconnectdb("dbname=db_pm host=localhost user=postgres password=postgres");
if (PQstatus(conn) == CONNECTION_BAD) {
puts("We were unable to connect to the database");
exit(0);
}
}
I'm trying to connect with PostgreSQL.
I compile this code with following command:
gcc -I/"d:\Program Files\PostgreSQL\" -L/"d:\Program Files\PostgreSQL\8.4\lib\" -lpq -o firstcpp.o firstcpp.cpp
This command is from following site:
http://www.mkyong.com/database/how-to-building-postgresql-libpq-programs/
And when I compile it I get following error:
/cygnus/cygwin-b20/H-i586-cygwin32/i586-cygwin32/bin/ld: cannot open -lpq: No such file or directory
collect2: ld returned 1 exit status
Does anyone help me?
Difek
You can try using forward slashes instead of backward slashes. And I have no idea about the first forward slash. Isn't it meant to be inside the quotes ? Eg -I"/d:/Program Files/PostgreSQL/"
Anyway, if you are using the gcc from cygwin, you could also try
-I"/cygdrive/d/Program Files/PostgreSQL"
And I'd do the same with that include (libpq-fe) - though apparently that is working, the error is in the linker.