nomad
nomad copied to clipboard
MATLAB building fails on macOS
My problem
I am building nomad on macOS for MATLAB. I hence ran
cmake -DBUILD_INTERFACE_MATLAB=ON -DMatlab_ROOT_DIR=/Applications/MATLAB_R2022b.app -S . -B build/release
This completed successfully. However, when building the library with
cmake --build build/release
I get the following error.
[ 99%] Linking CXX shared library nomadOpt.mexmaci64
Undefined symbols for architecture x86_64:
"_utIsInterruptPending", referenced from:
matlabEval::eval_x(NOMAD_4_2::EvalPoint&, NOMAD_4_2::Double const&, bool&) const in nomadmex.cpp.o
"_utSetInterruptPending", referenced from:
matlabEval::eval_x(NOMAD_4_2::EvalPoint&, NOMAD_4_2::Double const&, bool&) const in nomadmex.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [interfaces/Matlab_MEX/nomadOpt.mexmaci64] Error 1
make[1]: *** [interfaces/Matlab_MEX/CMakeFiles/nomadOpt.dir/all] Error 2
make: *** [all] Error 2
I set up mex to run with clang.
My architecture
- macOS: version 12.6 (Monterey, x86_64)
- clang: version 14.0.0 (clang-1400.0.29.102)
- MATLAB: version 9.13.0.2049777 (R2022b)
- CMake: version 3.24.1
Do you have any idea how I can fix my problem? Thank you very much for your help :grin:
My architecture is close to yours, except for clang version (clang-1300.0.29.30). I can compile with architecture x86_64 (by default I have arm64). But the compilation works fine.
I am not sure if there is just the utSetInterruptPending function missing. Could you try to comment the lines
` //Check for Ctrl-C
if ( utIsInterruptPending() )
{
utSetInterruptPending(false); /* clear Ctrl-C status */
mexPrintf("\nCtrl-C Detected. Exiting NOMAD...\n\n");
count_eval = false;
NOMAD::Step::setUserTerminate();
return false;
}`
This is around line 368 in $NOMAD_HOME/interfaces/Matlab_MEX/Source/nomadmex.cpp. This function is used for CTRL-C detection.
It now compiles, but MATLAB crashes every time I run nomadOpt. More precisely, I tried
nomadOpt(@(x)x^2,1)
Did I misunderstood the syntax and broke the MEX-file? Thanks :+1:
The syntax you used is not correct. Run the examples in $NOMAD_HOME/interfaces/Matlab_MEX/test_nomad_gerad.m to make sure that everything works normally. You can use the examples to work your problem.
Nevertheless, Matlab should not crash if the nomadOpt is called with the wrong syntax. I will look into that and also how to replace the utIsInterruptPending() function.
I understand. The tests runs on my machine, and produces
------------------------------------------------------------------
This is NOMAD v4.2.0
Authors: C. Audet, S. Le Digabel, V. Rochon Montplaisir and C. Tribes
MEX Interface C. Tribes 2021
Problem Properties:
# Decision Variables: 2
# Number of Objectives: 1
# Number of Nonlinear Constraints: 0
------------------------------------------------------------------
BBE OBJ
1 909
10 20
13 4.82
23 2.5
27 2.12
37 1.7
42 1.22
59 1
60 0.929419
63 0.80402
68 0.71065
72 0.694857
74 0.639846
76 0.631801
78 0.588927
80 0.5689
82 0.561994
84 0.505621
90 0.477985
91 0.461502
93 0.420715
97 0.400596
98 0.376996
99 0.359715
100 0.35004
A termination criterion is reached: Maximum number of blackbox evaluations (Eval Global) Success found and opportunistic strategy is used 100
Best feasible solution: #4590 ( 0.455 0.184 ) Evaluation OK f = 0.3500400000000000178 h = 0
Best infeasible solution: Undefined.
Blackbox evaluations: 100
Total model evaluations: 3664
Cache hits: 8
Total number of evaluations: 108
Feasible solution obtained
Thank you very much, Tom.