Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't Build MATLAB Interface (Can't find MATLAB) #63

Open
Arrowstar opened this issue Feb 10, 2022 · 7 comments
Open

Can't Build MATLAB Interface (Can't find MATLAB) #63

Arrowstar opened this issue Feb 10, 2022 · 7 comments
Labels
fix Issue fixed

Comments

@Arrowstar
Copy link

I receive the following error when I attempt to build the software on Linux (Linux Mint). For what it's worth, I've also tried this on CentOS and got the same error, and on Windows I got the same error until I specified the target platform with "-A x64".

I could use some help figuring out how to handle this. My version of CMake is up to date (3.16). I'm on MATLAB R2021a and I've already added the appropriate entry for this MATLAB version to the FindMATLAB cmake file.

adam@adam-VirtualBox:~/Desktop/nomad-v.4.2.0$ cmake -DTEST_OPENMP=OFF -DBUILD_INTERFACE_MATLAB=ON -S . -B build/release
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CHECK_START Configuring custom options
-- Installation prefix set to /home/adam/Desktop/nomad-v.4.2.0/build/release
CHECK_START Configuring for use of Sgtelib library
CHECK_PASS Sgtelib found. done
-- Compiling Nomad without OpenMP
CHECK_START Configuring build for library and batch mode examples
-- Add example library #1
-- Add example library #2
-- Add example library #3
-- Add example library single_obj_parallel
-- Add example library tests using Suggest And Observe
-- Add example batch #1
-- Add example batch #2
-- Add example batch single_obj
-- Add example batch surrogate sort
-- Add example batch single_obj_MPIparallel (MPI found).
CHECK_PASS done
-- C interface to Nomad NOT built
-- Python interface to Nomad NOT built
CHECK_START Configuring build for Matlab interface
CMake Error at /usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
Could NOT find Matlab (missing: Matlab_INCLUDE_DIRS Matlab_MEX_LIBRARY
Matlab_MEX_EXTENSION Matlab_ROOT_DIR Matlab_MX_LIBRARY MEX_COMPILER) (found
version "NOTFOUND")
Call Stack (most recent call first):
/usr/share/cmake-3.16/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
/usr/share/cmake-3.16/Modules/FindMatlab.cmake:1803 (find_package_handle_standard_args)
CMakeLists.txt:170 (find_package)

-- Configuring incomplete, errors occurred!

I've attached my CMakeOutput.log file, hopefully that will provide some insight.
CMakeOutput.log

Any help you can provide would be appreciated!

@ctribes
Copy link
Contributor

ctribes commented Feb 10, 2022

The error message that bothers me is "missing: Matlab_INCLUDE_DIRS Matlab_MEX_LIBRARY
Matlab_MEX_EXTENSION Matlab_ROOT_DIR Matlab_MX_LIBRARY MEX_COMPILER"
What happen if your run the "mex -setup" command in Matlab ? This is suppose to give some information about the available compilers and the mex config file.

I obtain:

>> mex -setup
Renamed options file '/home/ctribes/.matlab/R2021b/mex_C_glnxa64.xml' to '/home/ctribes/.matlab/R2021b/mex_C_glnxa64_backup.xml'.
MEX configured to use 'gcc' for C language compilation.

To choose a different language, execute one from the following:
 mex -setup C++ 
 mex -setup FORTRAN
>> mex -setup C++
Renamed options file '/home/ctribes/.matlab/R2021b/mex_C++_glnxa64.xml' to '/home/ctribes/.matlab/R2021b/mex_C++_glnxa64_backup.xml'.
MEX configured to use 'g++' for C++ language compilation.
>> 

@Arrowstar
Copy link
Author

Arrowstar commented Feb 10, 2022

The error message that bothers me is "missing: Matlab_INCLUDE_DIRS Matlab_MEX_LIBRARY Matlab_MEX_EXTENSION Matlab_ROOT_DIR Matlab_MX_LIBRARY MEX_COMPILER" What happen if your run the "mex -setup" command in Matlab ? This is suppose to give some information about the available compilers and the mex config file.

I obtain:

>> mex -setup
Renamed options file '/home/ctribes/.matlab/R2021b/mex_C_glnxa64.xml' to '/home/ctribes/.matlab/R2021b/mex_C_glnxa64_backup.xml'.
MEX configured to use 'gcc' for C language compilation.

To choose a different language, execute one from the following:
 mex -setup C++ 
 mex -setup FORTRAN
>> mex -setup C++
Renamed options file '/home/ctribes/.matlab/R2021b/mex_C++_glnxa64.xml' to '/home/ctribes/.matlab/R2021b/mex_C++_glnxa64_backup.xml'.
MEX configured to use 'g++' for C++ language compilation.
>> 

When I run that command in MATLAB and then select the "C++" option, here's what I get:

>> mex -setup
MEX configured to use 'gcc' for C language compilation.

To choose a different language, select one from the following:
 mex -setup C++ 
 mex -setup FORTRAN
MEX configured to use 'g++' for C++ language compilation.

@Arrowstar
Copy link
Author

Update:

I was able to get it to work, but only by setting the MATLAB root in the CMakeLists file (right before the find_package() call):

set(Matlab_ROOT_DIR "/usr/local/MATLAB/R2021a")

However, this is an advanced step that shouldn't be necessary. Any ideas why the code couldn't locate MATLAB on its own? I added the root directory to the PATH and it still didn't work as intended...

@ctribes
Copy link
Contributor

ctribes commented Feb 10, 2022

I was about to suggest this (set(Matlab_ROOT_Dir ...).

Clearly the find_package(Matlab ...) is not working properly with cmake 3.16. It can be the FindMatlab.cmake or where your matlab is installed.
I am using cmake 3.19 and once loaded, Matlab is in /home/Matlab/r2021b/

Can you be more specific about what is not working as intended ?

@ctribes
Copy link
Contributor

ctribes commented Feb 10, 2022

I just checked my environment variables :
MATLABROOT="/home/matlab/r2021b"
Maybe FindMatlab.cmake uses this variable to "find" matlab. Can you check that ?

@Arrowstar
Copy link
Author

Arrowstar commented Feb 10, 2022

I just checked my environment variables : MATLABROOT="/home/matlab/r2021b" Maybe FindMatlab.cmake uses this variable to "find" matlab. Can you check that ?

No joy, unfortunately. I have MATLABROOT set and added to PATH, but I still get the same error.

adam@adam-VirtualBox:~/Desktop/nomad-v.4.2.0$ echo $MATLABROOT
/usr/local/MATLAB/R2021a
adam@adam-VirtualBox:~/Desktop/nomad-v.4.2.0$ echo $PATH
/usr/local/MATLAB/R2021a:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
adam@adam-VirtualBox:~/Desktop/nomad-v.4.2.0$

@ctribes ctribes changed the title Can't Build MATLAB Interface on Linux (Can't find MATLAB) Can't Build MATLAB Interface (Can't find MATLAB) Mar 28, 2022
@ctribes
Copy link
Contributor

ctribes commented Mar 28, 2022

This issue also arises with OSX.

As mentioned previously, the first option is to set the MATLAB root in the CMakeLists file (right before the find_package() call):
set(Matlab_ROOT_DIR "/usr/local/MATLAB/R2021a")

Another way is to pass the variable to CMake during configuration:

cmake -DBUILD_INTERFACE_MATLAB=ON -DMatlab_ROOT_DIR=/Applications/MATLAB_R20xx.app -S. -B build/release

@ctribes ctribes added the fix Issue fixed label Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Issue fixed
Projects
None yet
Development

No branches or pull requests

2 participants