MEX compilation error with gcc 15.2. MATLAB version MATLAB2020b

14 次查看(过去 30 天)
I have updated gcc version to version 15.2 When I mex compile the code, the error related to matrix.h include files pop ups.
The error is undefined bool type.
I have added include of stdbool.h to the source as well and still the same error persist.
I have some other c files which are still passing on the same machine.

回答(1 个)

Aditya
Aditya about 1 hour 前
Hi Divya,
This is a common issue when compiling MEX files for MATLAB or Octave with newer versions of GCC (like GCC 15.x). The error about bool being undefined, even after including <stdbool.h>, is usually caused by a conflict between MATLAB's (or Octave's) own type definitions and those in the system headers.Root Cause
  • matrix.h (provided by MATLAB/Octave) sometimes defines its own bool type or expects an older C standard.
  • GCC 15.x is stricter and may expose conflicts between the C99 bool (from <stdbool.h>) and any custom bool definitions.
  • If you have #define bool or similar in your code or in matrix.h, it can cause this error.
1. Include Order Matters
Always include matrix.h before including <stdbool.h> or any other system headers
#include "matrix.h"
#include <stdbool.h>
2.Check for Redefinition
Make sure neither your code nor matrix.h is redefining bool.
If you see something like:
typedef int bool;
#define true 1
#define false 0
remove or guard it with:
#ifndef __cplusplus
#include <stdbool.h>
#endif
3.Check MATLAB/Octave Version Compatibility
Older versions of MATLAB/Octave may not be compatible with newer GCC.
  • Check if there's an update or patch for MATLAB/Octave for GCC 15.x support.
  • If not, consider downgrading GCC (e.g., to GCC 11 or 12) for MEX compilation.

类别

Help CenterFile Exchange 中查找有关 Octave 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by