I want to solve a problem in C++ which involves finding solutions to a system of equations. I saw that Intel's MKL package provides the necessary tools for that. I have downloaded the entire library and I've installed it.
First, I wanted to see if everything works, so compiling a simple example provided by intel (see the C source file here) was the first thing I've tried. It is a program that multiplies two matrices with the help of cblas_dgem function. However, I get a lot of warnings
and an error:
basavyr#Roberts-MacBook-Pro Desktop % g++ mkl-lab-solution.c
clang: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
In file included from mkl-lab-solution.c:30:
In file included from /usr/local/include/stdio.h:64:
/usr/local/include/_stdio.h:93:16: warning: pointer is missing a nullability type specifier
(_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
unsigned char *_base;
^
/usr/local/include/_stdio.h:93:16: note: insert '_Nullable' if the pointer may be null
unsigned char *_base;
^
_Nullable
/usr/local/include/_stdio.h:93:16: note: insert '_Nonnull' if the pointer should never be null
unsigned char *_base;
^
_Nonnull
/usr/local/include/_stdio.h:138:32: warning: pointer is missing a nullability type specifier
(_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int (* _Nullable _read) (void *, char *, int);
^
/usr/local/include/_stdio.h:138:32: note: insert '_Nullable' if the pointer may be null
int (* _Nullable _read) (void *, char *, int);
^
_Nullable
/usr/local/include/_stdio.h:138:32: note: insert '_Nonnull' if the pointer should never be null
int (* _Nullable _read) (void *, char *, int);
^
_Nonnull
/usr/local/include/_stdio.h:138:40: warning: pointer is missing a nullability type specifier
(_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int (* _Nullable _read) (void *, char *, int);
^
/usr/local/include/_stdio.h:138:40: note: insert '_Nullable' if the pointer may be null
int (* _Nullable _read) (void *, char *, int);
^
_Nullable
/usr/local/include/_stdio.h:138:40: note: insert '_Nonnull' if the pointer should never be null
int (* _Nullable _read) (void *, char *, int);
^
_Nonnull
/usr/local/include/_stdio.h:139:35: warning: pointer is missing a nullability type specifier
(_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
fpos_t (* _Nullable _seek) (void *, fpos_t, int);
^
/usr/local/include/_stdio.h:139:35: note: insert '_Nullable' if the pointer may be null
fpos_t (* _Nullable _seek) (void *, fpos_t, int);
^
_Nullable
/usr/local/include/_stdio.h:139:35: note: insert '_Nonnull' if the pointer should never be null
fpos_t (* _Nullable _seek) (void *, fpos_t, int);
^
_Nonnull
/usr/local/include/_stdio.h:140:32: warning: pointer is missing a nullability type specifier
(_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int (* _Nullable _write)(void *, const char *, int);
^
/usr/local/include/_stdio.h:140:32: note: insert '_Nullable' if the pointer may be null
int (* _Nullable _write)(void *, const char *, int);
^
_Nullable
/usr/local/include/_stdio.h:140:32: note: insert '_Nonnull' if the pointer should never be null
int (* _Nullable _write)(void *, const char *, int);
^
_Nonnull
/usr/local/include/_stdio.h:140:46: warning: pointer is missing a nullability type specifier
(_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int (* _Nullable _write)(void *, const char *, int);
^
/usr/local/include/_stdio.h:140:46: note: insert '_Nullable' if the pointer may be null
int (* _Nullable _write)(void *, const char *, int);
^
_Nullable
/usr/local/include/_stdio.h:140:46: note: insert '_Nonnull' if the pointer should never be null
int (* _Nullable _write)(void *, const char *, int);
^
_Nonnull
/usr/local/include/_stdio.h:144:18: warning: pointer is missing a nullability type specifier
(_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
struct __sFILEX *_extra; /* additions to FILE to not break ABI */
^
/usr/local/include/_stdio.h:144:18: note: insert '_Nullable' if the pointer may be null
struct __sFILEX *_extra; /* additions to FILE to not break ABI */
^
_Nullable
/usr/local/include/_stdio.h:144:18: note: insert '_Nonnull' if the pointer should never be null
struct __sFILEX *_extra; /* additions to FILE to not break ABI */
^
_Nonnull
In file included from mkl-lab-solution.c:30:
/usr/local/include/stdio.h:67:13: warning: pointer is missing a nullability type specifier
(_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
extern FILE *__stdinp;
^
/usr/local/include/stdio.h:67:13: note: insert '_Nullable' if the pointer may be null
extern FILE *__stdinp;
^
_Nullable
/usr/local/include/stdio.h:67:13: note: insert '_Nonnull' if the pointer should never be null
extern FILE *__stdinp;
^
_Nonnull
/usr/local/include/stdio.h:386:41: warning: pointer is missing a nullability type specifier
(_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int (* _Nullable)(void *, const char *, int),
^
/usr/local/include/stdio.h:386:41: note: insert '_Nullable' if the pointer may be null
int (* _Nullable)(void *, const char *, int),
^
_Nullable
/usr/local/include/stdio.h:386:41: note: insert '_Nonnull' if the pointer should never be null
int (* _Nullable)(void *, const char *, int),
^
_Nonnull
/usr/local/include/stdio.h:386:55: warning: pointer is missing a nullability type specifier
(_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int (* _Nullable)(void *, const char *, int),
^
/usr/local/include/stdio.h:386:55: note: insert '_Nullable' if the pointer may be null
int (* _Nullable)(void *, const char *, int),
^
_Nullable
/usr/local/include/stdio.h:386:55: note: insert '_Nonnull' if the pointer should never be null
int (* _Nullable)(void *, const char *, int),
^
_Nonnull
/usr/local/include/stdio.h:387:44: warning: pointer is missing a nullability type specifier
(_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
fpos_t (* _Nullable)(void *, fpos_t, int),
^
/usr/local/include/stdio.h:387:44: note: insert '_Nullable' if the pointer may be null
fpos_t (* _Nullable)(void *, fpos_t, int),
^
_Nullable
/usr/local/include/stdio.h:387:44: note: insert '_Nonnull' if the pointer should never be null
fpos_t (* _Nullable)(void *, fpos_t, int),
^
_Nonnull
/usr/local/include/stdio.h:388:41: warning: pointer is missing a nullability type specifier
(_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
int (* _Nullable)(void *));
^
/usr/local/include/stdio.h:388:41: note: insert '_Nullable' if the pointer may be null
int (* _Nullable)(void *));
^
_Nullable
/usr/local/include/stdio.h:388:41: note: insert '_Nonnull' if the pointer should never be null
int (* _Nullable)(void *));
^
_Nonnull
/usr/local/include/stdio.h:384:6: warning: pointer is missing a nullability type specifier
(_Nonnull, _Nullable, or _Null_unspecified) [-Wnullability-completeness]
FILE *funopen(const void *,
^
/usr/local/include/stdio.h:384:6: note: insert '_Nullable' if the pointer may be null
FILE *funopen(const void *,
^
_Nullable
/usr/local/include/stdio.h:384:6: note: insert '_Nonnull' if the pointer should never be null
FILE *funopen(const void *,
^
_Nonnull
mkl-lab-solution.c:85:15: warning: conversion from string literal to 'char *' is deprecated
[-Wc++11-compat-deprecated-writable-strings]
print_arr(N,"a", a);
^
mkl-lab-solution.c:86:15: warning: conversion from string literal to 'char *' is deprecated
[-Wc++11-compat-deprecated-writable-strings]
print_arr(N,"b", b);
^
mkl-lab-solution.c:87:15: warning: conversion from string literal to 'char *' is deprecated
[-Wc++11-compat-deprecated-writable-strings]
print_arr(N,"c", c);
^
16 warnings generated.
Undefined symbols for architecture x86_64:
"_cblas_dgemm", referenced from:
Dgemm_multiply(double*, double*, double*, int) in mkl-lab-solution-96315a.o
ld: symbol(s) not found for architecture x86_64
**clang: error:** linker command failed with exit code 1 (use -v to see invocation)
basavyr#Roberts-MacBook-Pro Desktop %
Compilation was done with the following command: g++ -m64 -I${MKLROOT}/include mkl-lab-solution.c
I am running macOS Catalina (10.15.3). I have no issues with my C++ compiler (I ran everything so far without issues)
Any ideas why is this happening and how can I solve the problem?
You need to link with mkl's libraries. Please refer to the mkl linker adviser to see the list of mkl's libs you need to link. here is the list to this adviser: https://software.intel.com/en-us/articles/intel-mkl-link-line-advisor.
Related
This question already has an answer here:
mex compilation error C2440: 'initializing': cannot convert from 'const mwSize *' to 'const int32_t *'
(1 answer)
Closed 6 months ago.
I was trying to compile the function c_eoverlap in matlab following the instruction here:
http://www.robots.ox.ac.uk/~vgg/research/affine/evaluation.html#eval_soft
Of course, it wouldn't work out... My Matlab version is 2018a which is pretty new and the gcc -v outputs the following
Also attach this long error log, as I am pretty new to C++, please let me know if there is any other information needed, appreciate for your help!
>> mex repeatability/c_eoverlap.cxx
Building with 'Xcode Clang++'.
Error using mex
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:34:14: error: cannot initialize
a variable of type 'const int *' with an rvalue of type 'const mwSize *' (aka 'const unsigned
long *')
int const *dims1 = mxGetDimensions(prhs[0]);
^ ~~~~~~~~~~~~~~~~~~~~~~~~
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:36:14: error: cannot initialize
a variable of type 'const int *' with an rvalue of type 'const mwSize *' (aka 'const unsigned
long *')
int const *dims2 = mxGetDimensions(prhs[1]);
^ ~~~~~~~~~~~~~~~~~~~~~~~~
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:38:14: error: cannot initialize
a variable of type 'const int *' with an rvalue of type 'const mwSize *' (aka 'const unsigned
long *')
int const *dims3 = mxGetDimensions(prhs[2]);
^ ~~~~~~~~~~~~~~~~~~~~~~~~
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:46:13: error: no matching
function for call to 'mxCreateNumericArray_730'
plhs[0] = mxCreateNumericArray(2, odim, mxDOUBLE_CLASS, mxREAL);
^~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:282:30: note: expanded from macro
'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^~~~~~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:1256:1: note: candidate function not
viable: no known conversion from 'int *' to 'const mwSize *' (aka 'const unsigned long *')
for 2nd argument
mxCreateNumericArray(mwSize ndim, const mwSize *dims, mxClassID classid, mxComplexity flag);
^
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:282:30: note: expanded from macro
'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:47:13: error: no matching
function for call to 'mxCreateNumericArray_730'
plhs[1] = mxCreateNumericArray(2, odim, mxDOUBLE_CLASS, mxREAL);
^~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:282:30: note: expanded from macro
'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^~~~~~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:1256:1: note: candidate function not
viable: no known conversion from 'int *' to 'const mwSize *' (aka 'const unsigned long *')
for 2nd argument
mxCreateNumericArray(mwSize ndim, const mwSize *dims, mxClassID classid, mxComplexity flag);
^
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:282:30: note: expanded from macro
'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:48:13: error: no matching
function for call to 'mxCreateNumericArray_730'
plhs[2] = mxCreateNumericArray(2, odim, mxDOUBLE_CLASS, mxREAL);
^~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:282:30: note: expanded from macro
'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^~~~~~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:1256:1: note: candidate function not
viable: no known conversion from 'int *' to 'const mwSize *' (aka 'const unsigned long *')
for 2nd argument
mxCreateNumericArray(mwSize ndim, const mwSize *dims, mxClassID classid, mxComplexity flag);
^
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:282:30: note: expanded from macro
'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:49:13: error: no matching
function for call to 'mxCreateNumericArray_730'
plhs[3] = mxCreateNumericArray(2, odim, mxDOUBLE_CLASS, mxREAL);
^~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:282:30: note: expanded from macro
'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^~~~~~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:1256:1: note: candidate function not
viable: no known conversion from 'int *' to 'const mwSize *' (aka 'const unsigned long *')
for 2nd argument
mxCreateNumericArray(mwSize ndim, const mwSize *dims, mxClassID classid, mxComplexity flag);
^
/Applications/MATLAB_R2018a.app/extern/include/matrix.h:282:30: note: expanded from macro
'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:198:3: warning: 'delete[]'
applied to a pointer that was allocated with 'new'; did you mean 'delete'?
[-Wmismatched-new-delete]
delete []tdesc_out;
^ ~~~
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:62:22: note: allocated with
'new' here
float *tdesc_out = new float[dims2[1]*dims1[1]];
^
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:199:3: warning: 'delete[]'
applied to a pointer that was allocated with 'new'; did you mean 'delete'?
[-Wmismatched-new-delete]
delete []tover_out;
^ ~~~
/Users/lucius/Desktop/ua/805/a1/repeatability/c_eoverlap.cxx:63:22: note: allocated with
'new' here
float *tover_out = new float[dims2[1]*dims1[1]];
^
2 warnings and 7 errors generated.
You need to add -compatibleArrayDims to your mex command:
mex -compatibleArrayDims c_eoverlap.cxx
The code is written for older MATLABs that used 32-bit integers (int) for array sizes. Nowadays these are 64-bits (mwSize). This option forces the interface to work like it did in the older MATLABs. See the mex documentation for details.
There are some scary warnings about using delete[] instead of delete. It's just warnings, so it will compile, but you don't know if the code will do what it is supposed to.
I read about this issue (seems quite common) for hours without finding any applicable solution to my situation. I understand that there might be a problem related to the included files and libraries, but I'm not actually able to find what's wrong.
It's an Arduino script that uses the MQTT client library. It works beautifully with the old PubSubClient.h lib.
Now I wanted to update the lib with a recent one. The function definitions are changed so I made the changes in the sketch and switched the lib in the Arduino/library directory, then restarted the Arduino IDE. I get lot of "error: 'argument' does not name a type" and I really don't know what to fix.
Here you can find the .h and .cpp files organization to understand what's happening.
//device.ino file
#include "device.h"
//device.h file
#ifndef DEVICE_H
#define DEVICE_H
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPUpdateServer.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
#include <jsmn.h>
#include <Arduino.h>
#include <pgmspace.h>
#include "mqtt.h"
#endif
mqtt.h file
#ifndef MQTT_H
#define MQTT_H
#include "device.h"
#endif
mqtt.cpp file
#include "mqtt.h"
WiFiClient wifi_client;
PubSubClient mqtt_client(wifi_client);
mqtt_client.setServer(mqtt_server, MQTT_BROKER_PORT);
mqtt_client.setCallback(mqtt_callback);
Finally the errors the compiler throws out:
mqtt.cpp:19: error:
'mqtt_client' does not name a type
mqtt_client.setServer(mqtt_server, MQTT_BROKER_PORT);
^
mqtt.cpp:20: error: 'mqtt_client' does not name a type
mqtt_client.setCallback(mqtt_callback);
^
sketch\mqtt.cpp: In function 'void mqtt_publish_mex(String, String, bool)':
mqtt.cpp:27: error: no matching function for call to 'PubSubClient::publish(String&, String&, bool&)'
if (mqtt_client.publish(topic, jmex, retained)) {
^
sketch\mqtt.cpp:27:54: note: candidates are:
In file included from sketch\Walvola.h:25:0,
from sketch\mqtt.h:4,
from sketch\mqtt.cpp:1:
C:\Users\Fabrizio & Dario\Documents\Arduino\libraries\pubsubclient\src/PubSubClient.h:130:12: note: boolean PubSubClient::publish(const char*, const char*)
boolean publish(const char* topic, const char* payload);
^
C:\Users\Fabrizio & Dario\Documents\Arduino\libraries\pubsubclient\src/PubSubClient.h:130:12: note: candidate expects 2 arguments, 3 provided
C:\Users\Fabrizio & Dario\Documents\Arduino\libraries\pubsubclient\src/PubSubClient.h:131:12: note: boolean PubSubClient::publish(const char*, const char*, boolean)
boolean publish(const char* topic, const char* payload, boolean retained);
^
C:\Users\Fabrizio & Dario\Documents\Arduino\libraries\pubsubclient\src/PubSubClient.h:131:12: note: no known conversion for argument 1 from 'String' to 'const char*'
C:\Users\Fabrizio & Dario\Documents\Arduino\libraries\pubsubclient\src/PubSubClient.h:132:12: note: boolean PubSubClient::publish(const char*, const uint8_t*, unsigned int)
boolean publish(const char* topic, const uint8_t * payload, unsigned int plength);
^
C:\Users\Fabrizio & Dario\Documents\Arduino\libraries\pubsubclient\src/PubSubClient.h:132:12: note: no known conversion for argument 1 from 'String' to 'const char*'
C:\Users\Fabrizio & Dario\Documents\Arduino\libraries\pubsubclient\src/PubSubClient.h:133:12: note: boolean PubSubClient::publish(const char*, const uint8_t*, unsigned int, boolean)
boolean publish(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained);
^
C:\Users\Fabrizio & Dario\Documents\Arduino\libraries\pubsubclient\src/PubSubClient.h:133:12: note: candidate expects 4 arguments, 3 provided
sketch\mqtt.cpp: In function 'void mqtt_log(String)':
mqtt.cpp:347: error: no matching function for call to 'PubSubClient::publish(const String&, String&)'
mqtt_client.publish(mqtt_controllers_topic_debug, json_string);
^
sketch\mqtt.cpp:347:70: note: candidates are:
In file included from sketch\Walvola.h:25:0,
from sketch\mqtt.h:4,
from sketch\mqtt.cpp:1:
C:\Users\Fabrizio & Dario\Documents\Arduino\libraries\pubsubclient\src/PubSubClient.h:130:12: note: boolean PubSubClient::publish(const char*, const char*)
boolean publish(const char* topic, const char* payload);
^
C:\Users\Fabrizio & Dario\Documents\Arduino\libraries\pubsubclient\src/PubSubClient.h:130:12: note: no known conversion for argument 1 from 'const String' to 'const char*'
C:\Users\Fabrizio & Dario\Documents\Arduino\libraries\pubsubclient\src/PubSubClient.h:131:12: note: boolean PubSubClient::publish(const char*, const char*, boolean)
boolean publish(const char* topic, const char* payload, boolean retained);
^
C:\Users\Fabrizio & Dario\Documents\Arduino\libraries\pubsubclient\src/PubSubClient.h:131:12: note: candidate expects 3 arguments, 2 provided
C:\Users\Fabrizio & Dario\Documents\Arduino\libraries\pubsubclient\src/PubSubClient.h:132:12: note: boolean PubSubClient::publish(const char*, const uint8_t*, unsigned int)
boolean publish(const char* topic, const uint8_t * payload, unsigned int plength);
^
C:\Users\Fabrizio & Dario\Documents\Arduino\libraries\pubsubclient\src/PubSubClient.h:132:12: note: candidate expects 3 arguments, 2 provided
C:\Users\Fabrizio & Dario\Documents\Arduino\libraries\pubsubclient\src/PubSubClient.h:133:12: note: boolean PubSubClient::publish(const char*, const uint8_t*, unsigned int, boolean)
boolean publish(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained);
^
C:\Users\Fabrizio & Dario\Documents\Arduino\libraries\pubsubclient\src/PubSubClient.h:133:12: note: candidate expects 4 arguments, 2 provided
In file included from sketch\mqtt.h:4:0,
from sketch\mqtt.cpp:1:
sketch\mqtt.cpp: In function 'void mqtt_callback(char*, byte*, unsigned int)':
mqtt.cpp:375: error: request for member 'payload_string' in 'payload', which is of non-class type 'byte* {aka unsigned char*}'
log(payload.payload_string());
^
sketch\Walvola.h:89:67: note: in definition of macro 'log'
#define log(mex) if (DEBUG) {Serial.println(walvola_time + "::" + mex);Serial.flush(); if(MQTT_DEBUG) {mqtt_log(walvola_time + "::" + mex);}}
^
mqtt.cpp:375: error: request for member 'payload_string' in 'payload', which is of non-class type 'byte* {aka unsigned char*}'
log(payload.payload_string());
^
sketch\Walvola.h:89:135: note: in definition of macro 'log'
#define log(mex) if (DEBUG) {Serial.println(walvola_time + "::" + mex);Serial.flush(); if(MQTT_DEBUG) {mqtt_log(walvola_time + "::" + mex);}}
^
mqtt.cpp:379: error: request for member 'payload_string' in 'payload', which is of non-class type 'byte* {aka unsigned char*}'
if (mqtt2JSONkvs(payload.payload_string())) {
^
mqtt.cpp:404: error: a function-definition is not allowed here before '{' token
{
^
mqtt.cpp:512: error: expected '}' at end of input
}
^
Più di una libreria trovata per "WiFiClient.h"
Usata: C:\Users\Fabrizio & Dario\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\ESP8266WiFi
Non usata: C:\Program Files (x86)\Arduino\libraries\WiFi
Non usata: C:\Program Files (x86)\Arduino\libraries\WiFi
Non usata: C:\Program Files (x86)\Arduino\libraries\WiFi
Non usata: C:\Program Files (x86)\Arduino\libraries\WiFi
exit status 1
'mqtt_client' does not name a type
Thanks for the help!
when writing
WiFiClient wifi_client;
PubSubClient mqtt_client(wifi_client);
mqtt_client.setServer(mqtt_server, MQTT_BROKER_PORT);
mqtt_client.setCallback(mqtt_callback);
the first two lines are quite ok => you are declaring global variables named wifi_client and mqtt_client
The problem comes with the calls
mqtt_client.setServer(mqtt_server, MQTT_BROKER_PORT);
mqtt_client.setCallback(mqtt_callback);
You can declare variables at global scope, but you cannot call functions outside a function (unless is for a global variable initialization), this is why you get this error. The example you point is different as the variables are in a function, thus calling methodes on them just after is legal: you are in a function context.
So you need to move your calls in the main() function, for example, so that the code gets valid.
That said, putting global variables in the header could make you more trouble is you include you file from different cpp files, the compiler will complain about multiple definitions, but that is not (yet) the question here.
I tried to use the yaafe library from http://yaafe.sourceforge.net/manual/install.html. Everything is installed and works fine. However I would like to use the matlab interface and I tried to compile the yaafemex.cpp provided using the following command mex yaafemex.cpp but I have this error on Matlab
Building with 'Xcode Clang++'.
Error using mex
/Users/TMAC/Documents/MATLAB/Add-Ons/Collections/Yaafe/yaafemex.cpp:107:22: error: no matching function for call
to 'mxCreateNumericArray_730'
mxArray* featdata = mxCreateNumericArray(2,dims,mxDOUBLE_CLASS,mxREAL);
^~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2017a.app/extern/include/matrix.h:1111:30: note: expanded from macro 'mxCreateNumericArray'
#define mxCreateNumericArray mxCreateNumericArray_730
^~~~~~~~~~~~~~~~~~~~~~~~
/Applications/MATLAB_R2017a.app/extern/include/matrix.h:782:1: note: candidate function not viable: no known conversion
from 'int [2]' to 'const size_t *' (aka 'const unsigned long *') for 2nd argument
mxCreateNumericArray_730(size_t ndim, const size_t *dims, mxClassID classid, mxComplexity flag);
^
1 error generated.
Portions of code (I haven't changed the intitial code provided by yaafe library)
yaafemex.cpp
/* write data */
int dims[2] = {buf->info().size , buf->availableTokens()};
mxArray* featdata = mxCreateNumericArray(2,dims,mxDOUBLE_CLASS,mxREAL); //line 107
double* featdataPtr = (double*) mxGetData(featdata);
buf->read(featdataPtr,buf->availableTokens());
buf->consumeTokens(buf->availableTokens());
mxSetField(feat,0,"data",featdata);
matrix.h
/*
* Create a numeric array and initialize all its data elements to 0.
*
* Similar to mxCreateNumericMatrix, in a standalone application,
* out-of-memory will mean a NULL pointer is returned.
*/
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C mxArray *
mxCreateNumericArray_730(size_t ndim, const size_t *dims, mxClassID classid, mxComplexity flag); //line 782
LIBMMWMATRIX_PUBLISHED_API_EXTERN_C mxArray *
mxCreateNumericArray_700(int ndim, const int *dims, mxClassID classid, mxComplexity flag);
int dims[2] = {buf->info().size , buf->availableTokens()};
Is signed, mxCreateNumericArray expects const size_t *, which is an unsigned numeric type. You either need to explicitly cast dims or define dims with the appropriate type.
Concretely, I'd edit the definition of dims in yaafe as follows:
size_t dims[2] = {static_cast<size_t>(buf->info().size) , static_cast<size_t>(buf->availableTokens())};
I'm trying to expose a overloaded function using boost::python.
the function prototypes are:
#define FMS_lvl2_DLL_API __declspec(dllexport)
void FMS_lvl2_DLL_API write(const char *key, const char* data);
void FMS_lvl2_DLL_API write(string& key, const char* data);
void FMS_lvl2_DLL_API write(int key, const char *data);
I'v seen this answer: How do I specify a pointer to an overloaded function?
doing this:
BOOST_PYTHON_MODULE(python_bridge)
{
class_<FMS_logic::logical_file, boost::noncopyable>("logical_file")
.def("write", static_cast<void (*)(const char *, const char *)>( &FMS_logic::logical_file::write))
;
}
results with the following error:
error C2440: 'static_cast' : cannot convert from 'overloaded-function' to 'void (__cdecl *)(const char *,const char *)'
None of the functions with this name in scope match the target type
trying the following:
void (*f)(const char *, const char *) = &FMS_logic::logical_file::write;
results:
error C2440: 'initializing' : cannot convert from 'overloaded-function' to 'void (__cdecl *)(const char *,const char *)'
None of the functions with this name in scope match the target type
what's wrong and how to fix it?
EDIT
I forgotten to mention a few things:
I'm using vs2010 pro on win-7
write is a member function of logical_file
FMS_logic is a namespace
Well the second attemp should work, if write is a pure function. From your code it seems you do have a memberfunction. Pointers to member-functions are ugly, you'd rather use a function object.
However: you would have to post the whole code, it is not clear whether write is a member-function or not.
Edit: if it is a member-function of FMS_logic::logical_file the syntax would be:
void (FMS_logic::logical_file::*f)(const char *, const char *) = &FMS_logic::logical_file::write;
This just applies for non-static member function, i.e. if a function is static or logical_file is just a namespace it is as you wrote it before.
Your code doesn't work because your function pointer type is wrong. You need to include all type qualifiers (your DLL qualifier is missing) and, as Klemens said, the class name. Putting this together, your code should read
.def("write", static_cast<void FMS_lvl2_DLL_API
(FMS_logic::logical_file::*)(const char *, const char *)>
(&FMS_logic::logical_file::write))
Thanks for the hint with the static_cast<>, I had the same problem as you, just without the dllexport, and after adding the static_cast it works :-)
anisha#linux-y3pi:~> g++ conditionVarTEST.cpp -Wall
conditionVarTEST.cpp: In function ‘int main()’:
conditionVarTEST.cpp:33:53: error: invalid conversion from ‘void*’ to ‘void* (*)(void*)’
conditionVarTEST.cpp:33:53: error: initializing argument 3 of ‘int pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)’
conditionVarTEST.cpp:34:53: error: invalid conversion from ‘void*’ to ‘void* (*)(void*)’
conditionVarTEST.cpp:34:53: error: initializing argument 3 of ‘int pthread_create(pthread_t*, const pthread_attr_t*, void* (*)(void*), void*)’
Line number 33 is this:
pthread_create (&A, NULL, (void *) &functionA, NULL);
Declaration of functionA is this:
void functionA (void*);
Its definition is:
void functionA (void* argA)
{
while (1)
{
pthread_mutex_lock (&mutexA);
if (count < 0)
{
pthread_cond_wait (&conditionVariableA, &mutexA);
}
else
{
// Do something.
std :: cout << "\nTime to enjoy!";
}
pthread_mutex_unlock (&mutexA);
}
}
If you look at the manual page you will see that the function argument is
void *(*start_routine) (void *)
That is, a pointer to a function which takes one void * argument and returns void *.
To get rid of your errors, change your function to return void *, and pass it without type-casting it. The return from the thread function can be a simple return NULL if you don't care about the value.
(void *) &functionA will cast your function pointer functionA which is of type void (*)(void*) to a simple void*. The later can't be converted to the first again, so the compiler reports an error. This is one of the reasons why you shouldn't use C-style casts.
Use pthread_create (&A, NULL, functionA, NULL); instead.
Also, the return type of a thread function should be void*, not void. So change void functionA(void*) to void* functionA(void*).
Use
pthread_create (&A, NULL, functionA, NULL);
instead of casting.
Also the function you use to pass to pthread_create should return a void* so to avoid any problems later, consider changing the function signature to accomodate this.
And as you are using a C++ compiler, you should use a function with C binding, as pthread_create expects a C function:
extern "C" void* functionA (void*);
C++ and C may have the same calling conventions on your current platform, but there is no guaranty, that this will be the case on other platforms or will be so in the future.