how to phrase openGL glDebugOutput / glDebugMessageCallback on linux platform - c++

I'm trying to debug my opengl program. and trying to use the error logging function. glDebugMessageCallback. However the only examples i can find use "typedef void (APIENTRY *DEBUGPROC)" or void APIENTRY glDebugOutput(...). and i know APIENTRY is a windows WINAPI based compiler flag, soo, how do i write a function that will work on linux using g++ compiler?... is it even possible?
if i try to it without that i get..
error: invalid conversion from ‘void* ()(GLenum, GLenum, GLuint, GLenum, GLsizei, const GLchar, void*)’ {aka ‘void* ()(unsigned int, unsigned int, unsigned int, unsigned int, int, const char, void*)’} to ‘GLDEBUGPROC’ {aka ‘void ()(unsigned int, unsigned int, unsigned int, unsigned int, int, const char, const void*)’} [-fpermissive]

According to the OpenGL 4.6 spec, Section 20.2 Debug Message Callback
callback must be a function whose prototype is of the form
void callback( enum source, enum type, uint id,
enum severity, sizei length, const char *message,
const void *userParam );
The definition does not contain any mentioning of APIENTRY. But even if so, most gl.h files will contain a definition similar to
#define APIENTRY GLAPIENTRY
But all of this has nothing to do with your problem. The real problem you have is that your function parameter do not match the debug message callback definition. As the error message states:
void* () (unsigned int, unsigned int, unsigned int, unsigned int, int, const char, void*)
does not match
void ()(unsigned int, unsigned int, unsigned int, unsigned int, int, const char, const void*)
Basically, you are missing a const for the last parameter.

Related

Arduino, understanding invalid conversion warning, unsigned char to char*

Edit:
Resolved, can't accept my answer for two days
I'm using PlatformIO to program a Arduino Nano to write a message to an OLED display.
I'm calling a function printWeight:
void printWeight(
float weight,
uint8_t scale=3,
uint8_t numbd=3,
uint8_t numad=2,
bool kg=false,
const char* description_text_line="Weight:",
uint8_t width_per_character=5+1,
uint8_t height_per_line=7+3
){
...
The function is centering the text by calculating the leading space leading_space and calls itself with a smaller scale (scale-1) if the message doesn't fit on the screen:
if(leading_space < 0){
printWeight(weight, scale-1, numbd, numad, description_text_line,
width_per_character, height_per_line);
return;
}
The code compiles and runs fine. However I'm getting the following warning that I don't know how to resolve:
src/main.cpp: In function 'void printWeight(float, uint8_t, uint8_t, uint8_t, bool, const char*, uint8_t, uint8_t)':
src/main.cpp:138:53: warning: invalid conversion from 'uint8_t {aka unsigned char}' to 'const char*' [-fpermissive]
width_per_character, height_per_line);
^
src/main.cpp:93:6: note: initializing argument 6 of 'void printWeight(float, uint8_t, uint8_t, uint8_t, bool, const char*, uint8_t, uint8_t)'
void printWeight(
^
How do I get rid of this warning?
Missing parameter...
Thanks to the ones commenting.

function pointer gives me “redeclared as different kind of symbol” error

I want to decloare a function pointer as:
char*(*palpr_recognize_rawimage)(OPENALPR*, unsigned char*, int, int, int, struct AlprCRegionOfInterest);
which is for a function prototype declared as:
char *openalpr_recognize_rawimage(OPENALPR *instance, unsigned char *pixelData, int bytesPerPixel, int imgWidth, int imgHeight, struct AlprCRegionOfInterest roi)
but I get this error on compilation:
‘char* (* palpr_recognize_rawimage)(OPENALPR*, unsigned char*, int, int, int, AlprCRegionOfInterest)’ redeclared as different kind of symbol
char*(*palpr_recognize_rawimage)(OPENALPR*, unsigned char*, int, int, int, struct AlprCRegionOfInterest);
^
One way to avoid retyping a complex definition and possibly making an error is to use decltype.
So, after your function prototype you can have:
using PFN = decltype(&openalpr_recognize_rawimage);
PFN myfunctionptr;
I've found the problem!
It was a simple typo in the typedef palpr_recognize_rawimage_type line:
I forgot to add the suffix _type to the type declaration and hence the type and the actual pointer had the same name - which obviously would cause troubles...
If I had looked past to first error from the compiler, I would have spotted the following: note: previous declaration and it would have been obvious that I mesed something up in my type naming.
--> It's worth it to not to only look at the first/top error but also look at least at the second one too - as you never know, it may provide a hint too!

c++: error: cannot convert ‘ns3::TracedValue<ns3::SequenceNumber<unsigned int, int> >’ to ‘uint32_t {aka unsigned int}

I am trying to cast TracedValue<uint32_t> m_bytesInFlight to uint32_t but I get the following error
error: cannot convert ‘ns3::TracedValue<ns3::SequenceNumber<unsigned int, int> >’ to ‘uint32_t {aka unsigned int}
Function prototype and variable declarations are
uint32_t UnAckDCount (void) const;
TracedValue<uint32_t> m_bytesInFlight {0}; //!< Bytes in flight
Here i am calling the function
uint32_t
TcpSocketBase::UnAckDCount () const
{
return m_tcb->m_highTxMark - (uint32_t) m_tcb->m_bytesInFlight;
}
Please suggest some method so that I can execute the return statement to get the result. Thanks in advance
Changing m_tcb->m_highTxMark to m_tcb->m_highTxMark.Get().GetValue() should work.
Seeing the compiler error, it's easy to figure out that variable m_highTxMark is of type ns3::TracedValue<ns3::SequenceNumber<unsigned int, int> >. I checked the documentation of ns3::TracedValue and ns3::SequenceNumber, they both have getter functions Get() and GetValue() respectively.
See:
https://www.nsnam.org/doxygen/classns3_1_1_traced_value.html
https://www.nsnam.org/doxygen/classns3_1_1_sequence_number.html

Compilation of Eigen3 with MKL

During an integration work of TensorFlow 1.1 with my ongoing C++ project on Ubuntu 16... I want to include a support to MKL and 64 bit integers.
I encountered a compilation problem in Eigen library while instantiate a template struct that has a direct call to MKL:
In file included from /usr/local/include/eigen3/unsupported/Eigen/CXX11/../../../Eigen/Core:526:0,
from /usr/local/include/eigen3/unsupported/Eigen/CXX11/Tensor:14,
from /home/drormeirovich/projects/tensorflow/third_party/eigen3/unsupported/Eigen/CXX11/Tensor:1,
from /home/drormeirovich/projects/tensorflow/tensorflow/core/framework/tensor.h:19,
from /home/drormeirovich/projects/tensorflow/tensorflow/cc/framework/ops.h:21,
from /home/drormeirovich/projects/tensorflow/tensorflow/cc/client/client_session.h:24,
from /home/drormeirovich/projects/my_project.cpp:10:
/usr/local/include/eigen3/unsupported/Eigen/CXX11/../../../Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h: In static member function ‘static void Eigen::internal::general_matrix_matrix_product<Index, double, LhsStorageOrder, ConjugateLhs, double, RhsStorageOrder, ConjugateRhs, 0>::run(Index, Index, Index, const double*, Index, const double*, Index, double*, Index, double, Eigen::internal::level3_blocking<double, double>&, Eigen::internal::GemmParallelInfo<Index>*)’:
/usr/local/include/eigen3/unsupported/Eigen/CXX11/../../../Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h:103:173: error: cannot convert ‘char*’ to ‘CBLAS_LAYOUT’ for argument ‘1’ to ‘void cblas_dgemm(CBLAS_LAYOUT, CBLAS_TRANSPOSE, CBLAS_TRANSPOSE, long long int, long long int, long long int, double, const double*, long long int, const double*, long long int, double, double*, long long int)’
BLASPREFIX##gemm(&transa, &transb, &m, &n, &k, &numext::real_ref(alpha), (const BLASTYPE*)a, &lda, (const BLASTYPE*)b, &ldb, &numext::real_ref(beta), (BLASTYPE*)res, &ldc); \
^
/usr/local/include/eigen3/unsupported/Eigen/CXX11/../../../Eigen/src/Core/products/GeneralMatrixMatrix_BLAS.h:106:1: note: in expansion of macro ‘GEMM_SPECIALIZATION’
GEMM_SPECIALIZATION(double, d, double, cblas_d)
^
For more details... My whole progress on this integration issue is in this link:
https://docs.google.com/document/d/1VFTdPJy59QTCTHO8NHMNmnO8AOoQhNXgWixas9KmLLM/edit?usp=drivesdk
Do I have to remove the support of MKL from Eigen3?
Any help would be appreciated...
disclaimer: I used to be an EasyBuild developer.
In EasyBuild we can build Eigen3 with MKL support, so this should work.
One of our contributers seems to have figured out that for eigen3 you need to copy the 'signature_of_eigen3_matrix_library' file into the path you use for your includes, see
https://github.com/hpcugent/easybuild-easyblocks/blob/master/easybuild/easyblocks/e/eigen.py
https://github.com/RLovelett/eigen/blob/master/signature_of_eigen3_matrix_library

Error on std::pair when compiling for mac / linux

I have a problem when compiling my code under Mac OS. This function declaration in my header file apparently causes some errors (it does work fine under Windows, though):
#include <string>
#include <vector>
#include <map>
#ifdef WIN32
#include <windows.h>
#endif
[...]
int setProcessEnvironment(
const wchar_t * procName,
const wchar_t * appName = NULL,
const wchar_t * workingDir = NULL,
const wchar_t * cmdArgs = NULL,
const std::vector< std::pair<const wchar_t *, int> > &systemEnvVars = std::vector< std::pair<const wchar_t *, int> >()
);
It looks like the compiler doesn't like the input for my pair - maybe I am missing some includes or what is the problem here?
I also don't fully understand the last line of this error message as my function description actually looks very different to the one in this error...
I am starting to think it may have to do with the default initialization, but what is the difference between the Mac and Windows compiler here?
26: error: expected ‘,’ or ‘...’ before ‘>’ token
26: error: wrong number of template arguments (1, should be 2)
/usr/include/c++/4.2.1/bits/stl_pair.h:68: error: provided for ‘template<class _T1, class _T2> struct std::pair’
26: error: template argument 1 is invalid
26: error: template argument 2 is invalid
26: error: default argument missing for parameter 6 of ‘int SysProcManager::setProcessEnvironment(const wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*, const std::vector<std::pair<const wchar_t*, int>, std::allocator<std::pair<const wchar_t*, int> > >&, int)’
159: error: prototype for ‘int SysProcManager::setProcessEnvironment(const wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*, const std::vector<std::pair<const wchar_t*, int>, std::allocator<std::pair<const wchar_t*, int> > >&)’ does not match any in class ‘SysProcManager’
26: error: candidates are: int SysProcManager::setProcessEnvironment(const wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*, const std::vector<std::pair<const wchar_t*, int>, std::allocator<std::pair<const wchar_t*, int> > >&, int)
138: error: int SysProcManager::setProcessEnvironment(const wchar_t*, const wchar_t*, const wchar_t*, const wchar_t*, const std::vector<const wchar_t*, std::allocator<const wchar_t*> >&)
Try #include <utility>
this was pointed out by André Caron:
Out of curiosity, can you typedef
std::vector< std::pair > EnvironmentBlock;
(change the name to your liking).
Replace the two instances in your
function declaration. See if that
clears up any parsing errors.
I am now declaring typedef std::vector< std::pair<const wchar_t*, int> > EnvironmentBlock; at the beginning and it does solve this problem on the Mac and it seems the compiler just can't deal with these nested types properly and screws things up - I did not see this problem on Linux or Windows, so maybe it's time to update my compiler (GCC 4.2).
Thank you Andre!
Several of the errors relate to the fact you have 2 definitions of setProcessEnvironment. One that takes as an added int on the end and another that takes in vector of wchar_t (not a vector of pairs).
I'd focus on these 2 problems to begin with. Failing that we need to see the rest of the code because some of the errors are being generated by code we can't see.