I'm using g++ under Fedora to compile an openGL project, which has the line:
textureImage = (GLubyte**)malloc(sizeof(GLubyte*)*RESOURCE_LENGTH);
When compiling, g++ error says:
error: ‘malloc’ was not declared in this scope
Adding #include <cstdlib>
doesn't fix the error.
My g++ version is: g++ (GCC) 4.4.5 20101112 (Red Hat 4.4.5-2)
You should use new in C++ code rather than malloc so it becomes new GLubyte* [RESOURCE_LENGTH] instead. When you #include <cstdlib> it will load malloc into namespace std, so refer to std::malloc (or #include <stdlib.h> instead).
'aligned_alloc' was not declared in this scope#117 Closed lsmainzeropened this issue Mar 27, 2018· 3 comments Closed 'aligned_alloc' was not declared in this scope#117
As you can see that the compiler also identified the line which has the error and also it has indicated that the variable “b” is out of the scope in the program. We have posted an image below in which you can clearly see that the Arduino IDE has highlighted the variable that it is unable to understand.
You should use new
in C++ code rather than malloc
so it becomes new GLubyte*[RESOURCE_LENGTH]
instead. When you #include <cstdlib>
it will load malloc
into namespace std
, so refer to std::malloc
(or #include <stdlib.h>
instead).
You need an additional include. Add <stdlib.h>
to your list of includes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With