I have built a mbed project with online ARMCC compiler, which has no complaints at all. After exporting projects to offline Keil MDK5. I got following complaints. Please advice if anyone knows how to remove/correct such issue.
SerialInterfaceProtocol/SerialInterfaceProtocol.h(16): error: #266: "CircularBuffer" is ambiguous
typedef CircularBuffer<uint8_t> SerialBuffer_t;
AlohaTransceiver/AlohaTransceiver.h(178): error: #266: "CircularBuffer" is ambiguous
CircularBuffer<AlohaFrame *> AlohaTxQueue;
AlohaTransceiver/AlohaTransceiver.cpp(44): error: #266: "CircularBuffer" is ambiguous
CircularBuffer<AlohaFrame *> AlohaRxQueue(10);
main.cpp(12): error: #266: "CircularBuffer" is ambiguous
CircularBuffer<uint8_t> SerialInputBuffer(128);
main.cpp(13): error: #266: "CircularBuffer" is ambiguous
CircularBuffer<uint8_t> SerialOutputBuffer(128);
I know CircularBuffer seems ambiguous if it has differenet types, but CircularBuffer is defined as a template, which should be used for different types? And online compiler passed, but MDK5 didn't, is there any compiler options should be enabled ?
The CircularBuffer is defined in RingBuffer.h
#ifndef RINGBUFFER_H_
#define RINGBUFFER_H_
#define DEFAULT_MAX_BUFFER_SZ 64
#include <stdint.h>
#include <stdlib.h>
template <typename T>
class CircularBuffer
{
private:
const size_t buffer_size;
size_t read_ptr;
size_t write_ptr;
size_t count;
// mutex lock
bool mux;
// overflow
bool is_over_flow;
// container
T *data;
public:
CircularBuffer(const size_t size=DEFAULT_MAX_BUFFER_SZ);
~CircularBuffer();
// psudo mutex
bool isLocked();
void lock();
void unlock();
// enqueue and dequeue
void enqueue(T in);
T dequeue();
// pointer operation
size_t getReadPtr();
size_t getWritePtr();
size_t getCounter();
// overflow
bool getOverFlow();
void clearOverFlow();
// operation
T first();
T last();
// random access
T operator[](size_t idx);
};
#endif
There are two CircularBuffer in the project, one is in mbed OS, the other is in user code. Merge them, or rename one of them.
Related
I'm trying to use emscripten to compile a c++ class and expose bindings. I'm running into an error from the compiler.
#include <emscripten/bind.h>
#include <emscripten/emscripten.h>
using namespace emscripten;
class MyClass {
private:
int _year;
int _month;
int _day;
public:
MyClass() { }
MyClass(int year, int month, int day);
int getMonth();
void setMonth(int);
int getYear();
void setYear(int);
int getDay();
void setDay(int);
bool isLeapYear();
int daysInMonth();
void increment();
void decrement();
};
EMSCRIPTEN_BINDINGS(my_sample_class) {
class_<MyClass>("MyClass")
.constructor<>()
.constructor<int, int, int>()
.function("getMonth", &MyClass::getMonth)
.function("increment", &MyClass::increment)
.function("decrement", &MyClass::decrement)
.property("year",&MyClass::getYear, &MyClass::setYear )
//.property("month", &MyClass::getMonth, &MyClass::setMonth )
//.property("day",&MyClass::getDay, &MyClass::setDay )
;
}
The compiler has no problems with the constructors or the function binding. I run into a problem with the property binding. I only have one uncommented to minimize the errors that I get back (they are just repeats of the same error but for different lines). Here are the errors that I'm getting back.
In file included from MyDate.cpp:1:
In file included from ./MyDate.h:2:
emscripten/bind.h:1393:26: error: implicit instantiation of undefined template 'emscripten::internal::GetterPolicy<int (MyClass::*)()>'
auto gter = &GP::template get<ClassType>;
^
./MyDate.h:37:6: note: in instantiation of function template specialization 'emscripten::class_<MyClass, emscripten::internal::NoBaseClass>::property<int (MyClass::*)(), void (MyClass::*)(int)>' requested here
.property("year",&MyClass::getYear, &MyClass::setYear )
^
emscripten/bind.h:569:16: note: template is declared here
struct GetterPolicy;
^
emscripten/bind.h:1399:33: error: implicit instantiation of undefined template 'emscripten::internal::GetterPolicy<int (MyClass::*)()>'
TypeID<typename GP::ReturnType>::get(),
^
emscripten\1.38.21\system\include\emscripten/bind.h:569:16: note: template is declared here
struct GetterPolicy;
^
2 errors generated.
shared:ERROR: compiler frontend failed to generate LLVM bitcode, halting
I've looked up binding examples and it appears I'm using the right syntax. Does any one have any idea of what I might be doing wrong?
Found the problem!
The getter functions must be marked as const to avoid these errors.
EX:
int getMonth() const;
I have created a class that abstracts a SPI flash chip library called SerialFlash by creating an abstract class of Print.h. When I try to print to this by using the ArduinoJson library, I get an error:
src/FlashMemory.cpp:99:36: error: no matching function for call to 'ArduinoJson::JsonObject::printTo(<unresolved overloaded function type>)'
root.printTo(serialFlashPrint);
^
lib/ArduinoJson/include/ArduinoJson/Internals/../Internals/JsonPrintable.hpp:34:10: note: size_t ArduinoJson::Internals::JsonPrintable<T>::printTo(Print&) const [with T = Ardu
inoJson::JsonObject; size_t = unsigned int]
size_t printTo(Print &print) const {
^
lib/ArduinoJson/include/ArduinoJson/Internals/../Internals/JsonPrintable.hpp:34:10: note: no known conversion for argument 1 from '<unresolved overloaded function type>' to
'Print&'
The file referenced in the error above is here: https://github.com/bblanchon/ArduinoJson/blob/master/include/ArduinoJson/Internals/JsonPrintable.hpp
This is the header file for the class:
#include <Arduino.h>
#include <SerialFlash.h>
#include "Print.h"
#ifndef _SerialFlashPrint_h_
#define _SerialFlashPrint_h_
class SerialFlashPrint : public Print {
public:
SerialFlashPrint(SerialFlashFile *file);
virtual size_t write(uint8_t);
virtual size_t write(const uint8_t *buffer, size_t size);
private:
char buf[1];
uint16_t _current_byte;
SerialFlashFile * _file;
};
#endif
And the cpp file:
#include "serialFlashPrint.h"
SerialFlashPrint::SerialFlashPrint(SerialFlashFile * file) : Print() {
this->_file = file;
this->_current_byte = 0;
}
size_t SerialFlashPrint::write(uint8_t c) {
if(_current_byte == 0){
_file->erase();
_file->seek(0);
}
sprintf(buf, "%c", c);
_file->write(buf, 1);
_current_byte++;
return 0;
}
size_t SerialFlashPrint::write(const uint8_t *buffer, size_t size){
_file->erase();
_file->seek(0);
_file->write(buffer, size);
_file->write(NULL, 1);
return 0;
};
Generally, you use print function as: the root.printTo(Serial). This code is based upon an abstraction (which I got to work previously) called Chunked output that can be seen here: https://github.com/bblanchon/ArduinoJson/wiki/Bag-of-Tricks
Does anyone have any clues for me to figure out why I am getting <unresolved overloaded function type> instead of Print&?
<unresolved overloaded function type> means that the compiler found a function with several overloads and doesn't know which one to use.
You most likely have several serialFlashPrint() in your code or libraries.
If not, then you may have triggered the Most vexing parse:
SerialFlashPrint serialFlashPrint; // <- creates an instance of SerialFlashPrint
SerialFlashPrint serialFlashPrint(); // <- declares a function returning a SerialFlashPrint
I tried to compile flann by uses Make method from pack of another codes but I got this error about protected functions in one of the flann binary files './flann/util/matrix.h:75'
Can any one help me to fix this error?
I'm really new in programming, plz be simple as u can! :P
g++ -I. -Iflann/src/cpp -c -o src/main.o src/main.cpp
In file included from ./boost/asio/async_result.hpp:18,
from ./boost/asio.hpp:20,
from src/common.hpp:30,
from src/main.cpp:9:
./boost/asio/detail/config.hpp:367:5: warning: #warning Please define _WIN32_WIN NT or _WIN32_WINDOWS appropriately.
./boost/asio/detail/config.hpp:368:5: warning: #warning For example, add -D_WIN32_WINNT=0x0501 to the compiler command line.
./boost/asio/detail/config.hpp:369:5: warning: #warning Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP target).
./flann/util/matrix.h: In function 'int cbir::main(int, char**)':
./flann/util/matrix.h:75: error: 'flann::uchar* flann::Matrix_::data' is protected
src/main.cpp:39: error: within this context
Makefile:43: recipe for target `src/main.o' failed
make: *** [src/main.o] Error 1
This is matrix.h :
#ifndef FLANN_DATASET_H_
#define FLANN_DATASET_H_
#include "flann/general.h"
#include <stdio.h>
namespace flann
{
typedef unsigned char uchar;
class Matrix_
{
public:
Matrix_() : rows(0), cols(0), stride(0), data(NULL)
{
};
Matrix_(void* data_, size_t rows_, size_t cols_, flann_datatype_t type, size_t stride_ = 0) :
rows(rows_), cols(cols_), stride(stride_)
{
data = static_cast<uchar*>(data_);
if (stride==0) stride = flann_datatype_size(type)*cols;
}
inline void* operator[](size_t index) const
{
return data+index*stride;
}
void* ptr() const
{
return data;
}
size_t rows;
size_t cols;
size_t stride;
flann_datatype_t type;
protected:
uchar* data;
};
template <typename T>
class Matrix : public Matrix_
{
public:
typedef T type;
Matrix() : Matrix_()
{
}
Matrix(T* data_, size_t rows_, size_t cols_, size_t stride_ = 0) :
Matrix_(data_, rows_, cols_, flann_datatype<T>::value, stride_)
{
}
FLANN_DEPRECATED void free()
{
fprintf(stderr, "The flann::Matrix<T>::free() method is deprecated "
"and it does not do any memory deallocation any more. You are"
"responsible for deallocating the matrix memory (by doing"
"'delete[] matrix.ptr()' for example)");
}
inline T* operator[](size_t index) const
{
return reinterpret_cast<T*>(static_cast<uchar*>(Matrix_::data)+index*stride);
// return (T*)(Matrix_::operator [](index));
}
T* ptr() const
{
return reinterpret_cast<T*>(Matrix_::data);
}
};
}
#endif //FLANN_DATASET_H_
You should be using Matrix<T> instead of the untyped Matrix_ class. Then you can use ptr to get a typed pointer to the data, or the [] operator to get access to a specific element.
I'm trying to have MAGMA as backend for Eigen in the same way it does already support MKL. While doing so I bump into the error above. The relevant snippets below:
template <>
/*ERROR IN THIS LINE >>>>>*/ inline void assign_scalar_eig2magma<magmaDoubleComplex,dcomplex>(magmaDoubleComplex& magmaScalar, const dcomplex& eigenScalar) {
magmaScalar.x=eigenScalar.real();
magmaScalar.y=eigenScalar.imag();
}
and the magmaDoubleComplex is defined in magma_types.h:
// ========================================
// define types specific to implementation (CUDA, OpenCL, MIC)
// define macros to deal with complex numbers
#if HAVE_CUBLAS
#include <cublas.h>
typedef cudaStream_t magma_queue_t;
typedef cudaEvent_t magma_event_t;
typedef int magma_device_t;
typedef cuDoubleComplex magmaDoubleComplex;
typedef cuFloatComplex magmaFloatComplex;
As far as I can see magmaDoubleComplex is declared but this doesn't seem to be the issue here ...
UPDATE: Indeed my mistake, here the template definition is "mkl" and it should be "magma".
template<typename MAGMAType, typename EigenType>
static inline void assign_scalar_eig2mkl(MAGMAType& magmaScalar, const EigenType& eigenScalar) {
magmaScalar=eigenScalar;
}
I want to use a boost::ptr_map inside a specific class which stores instances of itself. However, please consider the following example:
#include <boost/checked_delete.hpp>
#include <boost/ptr_container/ptr_map.hpp>
class foo
{
friend void boost::checked_delete<>(foo*);
~foo() {}
};
int main()
{
boost::checked_delete(new foo); // OK
boost::ptr_map<int, foo> foo_map; // error C2248: 'foo::~foo' : cannot access private member declared in class 'foo'
return 0;
}
The error happens at the following line
// verify that types are complete for increased safety
template<class T> inline void checked_delete(T * x)
{
// intentionally complex - simplification causes regressions
typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
(void) sizeof(type_must_be_complete);
delete x; // error C2248
}
What exactly is going on here? Shouldn't it work? I assume that the problem is that templates are defined in the compilation unit they are included in and boost::checked_delete is called from another compilation unit in the implementation source of bosst::ptr_map. So, it's not the same function I declared as a friend.
However, is there a workaround for this problem?
Try this syntax when declaring the friend:
template <class T>
friend void boost::checked_delete(T*);
Here is the start of the huge error message* from GCC, which is the start of the chain of instantiations (usually, and in this case):
In file included from main.cpp:1:0:
main.cpp: In function 'void boost::checked_delete(T*) [with T = const foo]':
Adding
friend void boost::checked_delete<>(foo const*);
makes the code compile.
(*): 13 lines and 3510 characters for 270 chars/line