MEX compilation error with gcc 15.2. MATLAB version MATLAB2020b

14 vues (au cours des 30 derniers jours)
Divya
Divya le 16 Déc 2025 à 9:50
Réponse apportée : Aditya il y a environ 22 heures
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.

Réponses (1)

Aditya
Aditya il y a environ 22 heures
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.

Catégories

En savoir plus sur Octave dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by