- Install Full MATLAB (Not Just the Runtime)The MATLAB Engine API is not fully supported with only the MATLAB Runtime. Please ensure you are working with a complete MATLAB installation (e.g., C:\Program Files\MATLAB\R2025a).
- Configure Environment VariablesAdd the following directory to the Windows system PATH environment variable:
engOpen() fails when called from CodeBlocks on Windows 11
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
My projects is:
C:\Users\jim\Documents\CodeBlocksProjects\1\ 1.cbp.
The main is basically:
#include <stdio.h>
#include <stdlib.h>
#include "engine.h" // Path to MATLAB engine.h
int main()
{
Engine *ep;
// Start the MATLAB Engine
if (!(ep = engOpen(NULL))) {
fprintf(stderr, "\nCan't start MATLAB engine.\n");
return EXIT_FAILURE;
}
...
return EXIT_SUCCESS;
}
The MATLAB Runtime includes are here:
C:\Program Files\MATLAB\MATLAB Runtime\R2025a\extern\include
The libs are here:
C:\Program Files\MATLAB\MATLAB Runtime\R2025a\extern\lib\win64\mingw64
For “Search directories” > “Compiler”, I have:
C:\Program Files\MATLAB\MATLAB Runtime\R2025a\extern\include
C:\Program Files\MATLAB\MATLAB Runtime\R2025a\bin\win64
I have the following “Link libraries”:
C:\Program Files\MATLAB\MATLAB Runtime\R2025a\extern\lib\win64\mingw64\libmat.lib
C:\Program Files\MATLAB\MATLAB Runtime\R2025a\extern\lib\win64\mingw64\libeng.lib
C:\Program Files\MATLAB\MATLAB Runtime\R2025a\extern\lib\win64\mingw64\libmx.lib
C:\Program Files\MATLAB\MATLAB Runtime\R2025a\bin\win64\libeng.dll
C:\Program Files\MATLAB\MATLAB Runtime\R2025a\bin\win64\libmx.dll
It kept saying it couldn’t find the dll’s, so I copied them all of them from “C:\Program Files\MATLAB\MATLAB Runtime\R2025a\bin\win64\” into “C:\Users\jim\Documents\CodeBlocksProjects\1\bin\Debug\”.
Now “engOpen(NULL)” fails.
Any ideas?
0 commentaires
Réponses (2)
Ruchika Parag
le 21 Juil 2025
Hi @Jim, the engOpen(NULL) function requires access to a full MATLAB installation, not just the MATLAB Runtime. While the Runtime provides shared libraries, it does not include components required to launch or interface with the engine programmatically.
The MATLAB Engine executable and required dynamic libraries must be discoverable at runtime via the system PATH environment variable. Copying DLLs directly into the output directory is not a reliable or supported solution and may lead to unpredictable behavior.
Resolution Steps
C:\Program Files\MATLAB\R2025a\extern\bin\win64
3. This allows the operating system to resolve MATLAB Engine dependencies at runtime.
4. Remove Manually Copied DLLsDelete any .dll files you may have copied into your project directory. They can interfere with proper loading and may result in version mismatches.
5. Restart Code::Blocks and Rebuild the ProjectAfter modifying the environment variables, restart Code::Blocks to inherit the updated system PATH. Then rebuild and run your application.
Following these steps should allow engOpen(NULL) to succeed and launch the MATLAB Engine as expected.
If the issue persists, verify that MATLAB is installed correctly, the environment variable was set at the system level (not just the user level), and that your application has permission to access MATLAB processes. Hope this helps!
0 commentaires
Voir également
Catégories
En savoir plus sur Call MATLAB from C 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!