MEX compilation error with gcc 15.2. MATLAB version MATLAB2020b

조회 수: 18 (최근 30일)
Divya
Divya 2025년 12월 16일 9:50
답변: Aditya 2025년 12월 19일 5:01
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 2025년 12월 19일 5:01
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