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

Compilation of MATLAB toolbox fails for non-default MATLAB paths (Unix only) #126

Closed
VGab opened this issue Sep 30, 2019 · 8 comments
Closed

Comments

@VGab
Copy link

VGab commented Sep 30, 2019

While compiling GTSAM and the dedicated matlab toolbox a few hours ago, I encountered the issue that mex.h could not have been found.

While this bug stems from a customized problem at my PC, the quick bug fix may be of help for others or can be added as an additional options to the CMake files in a future release

Description

I followed the instructions on the installation page as well as the dedicated readme in the matlab sections. Nonethless, the compilation terminated as seen below
gtsam_compile_problem

Steps to reproduce

The problem in here lies presumably in my custom setup, where MATLAB is not installed in the standard unix location, i.e. /usr/local/MatlabRelease/, but mounted from a network share within a lab environment.
So in order to reproduce this error,

  1. alter the location of Matlab during installation to
     mv /usr/local/MatlabR20DDs /mnt/MatlabR20DDs
  2. follow the steps from the installation section and run the compilation process.

Environment

The problem occurred on

  • Linux Kubuntu 18.04 LTS system (Kernel 4.15.0-55-generic
  • Python interpreter set to Python 2.7.15+
  • Matlab version R2019a
  • gcc-version (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
  • cmake version 3.10.2

Additional information

quick and dirty fix

The compilation was successfully run after adding the Matlab c-headers directly into the CMakeLists.txt file in line 401 and 424

# Build wrap
if (GTSAM_BUILD_WRAP)
    include_directories("/mnt/MatlabR20DDs/extern/include")
    add_subdirectory(wrap)
endif(GTSAM_BUILD_WRAP)
[...]
# Matlab toolbox
if (GTSAM_INSTALL_MATLAB_TOOLBOX)
    include_directories("/mnt/MatlabR20DDs/extern/include")
    add_subdirectory(matlab)
endif()

Preferably one could introduce a new option to the CMakeLists, but I assumed this to be a very specific and rare error, thus preferring to pinpoint to the quick fix above.

@VGab
Copy link
Author

VGab commented Sep 30, 2019

Sorry in case this bug is better to be be posted in the google group instead. But as I did not have access over there i was afraid of forgetting to report the problem otherwise.

@varunagrawal
Copy link
Collaborator

varunagrawal commented Sep 30, 2019

Or you could just update the CMake Prefix Path before running cmake.

export CMAKE_PREFIX_PATH=/mnt/MatlabR20DDs/extern:$CMAKE_PREFIX_PATH

https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/Useful-Variables

@varunagrawal
Copy link
Collaborator

This is pretty much a custom case for you and can be easily fixed with some cmake cleverness, rather than a GTSAM bug. I vote to close this.

@dellaert
Copy link
Member

dellaert commented Oct 1, 2019

Thanks @VGab and @varunagrawal ! I think we should not close it yet. At the very least we should see whether Varun’s suggestion works, and then we should add it into docs and on the website. but, actually, i’m not in love with doing this via export. Can this be done on the cmake command line as well?

@mikesheffler
Copy link
Contributor

Looking at CMake-gui on Windows, I see MATLAB_ROOT set to C:/Program Files/MATLAB/R2019a.

So, would

$ cmake -DMATLAB_ROOT=:/Program Files/MATLAB/R2019a

be the shell equivalent (let's pretend this is Linux for a moment)? I'm awful at following CMake rabbit holes ...

@VGab
Copy link
Author

VGab commented Oct 1, 2019

Thanks for denoting this @mikesheffler. I was not aware of that as the MATLAB ROOT variable is not shown by default in ccmake but only after an initial conifguration with the GTSAM_INSTALL_MATLAB_TOOLBOX flag set to `ON``.
Nonetheless, running

cmake -DMEX_COMMAND=/usr/MatlabR20DDs/bin/mex \
           -DMATLAB_ROOT=/mnt/MatlabR20DDs  \
           -DGTSAM_INSTALL_MATLAB_TOOLBOX=ON  ..

circumvents the nonsense I claimed above and does resolve this "issue". I support @varunagrawal's claim that this issue is more of a rare and custom case problem and can be closed, but in order to make this problem visible to all users, one could add

message(STATUS "MATLAB toolbox flags                                      ")
print_config_flag(${GTSAM_INSTALL_MATLAB_TOOLBOX}      "Install matlab toolbox         ")
print_config_flag(${GTSAM_BUILD_WRAP}                  "Build Wrap                     ")
if (${GTSAM_INSTALL_MATLAB_TOOLBOX})
    message(STATUS "  MATLAB ROOT set to             : ${MATLAB_ROOT}")
    message(STATUS "  MEX command set to             : ${MEX_COMMAND}")
endif()

in line 576-582 at the top-level CMakeLists.txt. I think this is not worth a pull request and leave it up to you if this should be added or not.

Edit note:
I just reran the make install command with the settings above and discovered that the source of the error was actually due to a falsely set MEX_COMMAND=/usr/bin/mex variable. The command and output has been adjusted accordingly and could successfully install gtsam.

@ProfFan
Copy link
Collaborator

ProfFan commented Oct 1, 2019

Think we should print MEX compiler and MATLAB path as @VGab suggested, as this is also what OpenCV does. I will prepare a PR shortly.

@varunagrawal
Copy link
Collaborator

The CMake printing was added by #393.

varunagrawal added a commit that referenced this issue Oct 25, 2021
0ab10c359 Fix pyparsing version and replace `create_symlinks` with `copy_directory` (#128)
230a3c967 Merge pull request #127 from borglab/feature/template-instantiator
cc7d9a8b4 breakdown template instantiator into smaller submodules
59536220a Merge pull request #126 from borglab/feature/instantiation-tests
7ee715ecc add type info to template_instantiator
b367ed93d tests for InstantiationHelper
e41cfd50e tests for InstantiatedGlobalFunction
1837982a7 tests for InstantiatedClass
a7e3678a3 tests for InstantiatedStaticMethod
da06c53f7 tests for InstantiatedMethod
c645c143c tests for InstantiatedConstructor
b8a046267 tests for InstantiatedDeclaration
af80c9d04 finish all tests for namespace level instantiation
d6085c37a add tests for high level template instantiation
f7ae91346 add docs and utility method
d90abb52b Merge pull request #125 from borglab/feature/templated-static
58cdab20d clean up
247cea727 add helper for multilevel instantiation
761f588e4 update tests
81e5d5d19 update pybind wrapper to use new way
96d1575d8 streamlined way of instantiating template for class methods
1e4e88799 add to_cpp method for Method
485d43138 add the test fixtures
8cb943635 support instantiation of static method templates
84ef6679b add template to static method parser

git-subtree-dir: wrap
git-subtree-split: 0ab10c359a6528def20eddc60aced74a04250419
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants