Closed bemilio closed 4 years ago
cc @diegoferigo
I guess this can be related to https://github.com/robotology/blockfactory/issues/4 .
The only related issue that I found online is:
Yes it is related to #4. Blockfactory ships a vendored version of FindMatlab.cmake
, I would try to rename that file from the cmake
folder and check what happens with the default version. 3.12
should be recent enough to have the latest fixes on symbol visibility (I should double check though).
I suspect the the FindMatlab.cmake
does not handle as it should the 2018a
version. Unfortunately keeping track of all Matlab version is quite demanding. If with the upstream version still doesn't work, we should fix a f2f session.
I suspect the issue is in the CMake's upstream version of FindMatlab
module. We experienced the same problem in https://github.com/robotology-dependencies/qpOASES, that recently vendored the latest version of FindMatlab.cmake
from CMake's upstream, see https://github.com/robotology-dependencies/qpOASES/pull/11 .
The problem seems that "something" is looking for the mexCreateMexFunction
and the other functions referenced in the linker error, but those functions are not defined. With @bemilio I briefly tried to find that in some part of the code, but I was unable to find this symbol referenced in any C/C++ file. After checking a bit the recent history of the FindMatlab.cmake
file, I think that these errors can be related to the fact that all those functions are explicitly exported in https://github.com/robotology/blockfactory/blob/master/cmake/FindMatlab.cmake#L1031 (see https://gitlab.kitware.com/cmake/cmake/issues/17971 for the related CMake's MR). I think it would be nice to comment the assignment of link_flags in https://github.com/robotology/blockfactory/blob/master/cmake/FindMatlab.cmake#L1031, and see how the error changes.
Another test I would do is to uncomment the commented assign in https://github.com/robotology/blockfactory/blob/master/cmake/FindMatlab.cmake#L962 and see if that fix something.
I had a look today on the setup and I didn't mange to solve the problem. I was suspecting that somehow the following section was not executed:
But instead it is. Also Matlab_HAS_CPP_API
is set, and the symbols should be properly exported. However the linker complains.
I also checked if upstream there is an updated version of FindMatlab.cmake
. There are minor differences wrt our vendored file, nothing related to this section though.
Commenting out the lines that force the export of those symbols solves the linking error. However, there is a problem with:
Ok I managed to track down the problem (there are two independent problems).
Problem 1: FindMatlab.cmake
: Commenting out this block fixes the linking problem.
Problem 2: extern symbol: Changing the following line
to
const std::string BlockOptionPrioritizeOrder = "wbt.BlockOptionPrioritizeOrder";
fixes the complaints about the extern symbol. Using inline does not work because the compiler would require C++17.
It looks like updating CMake from 3.12.0 to 3.14.4 has fixed the last (generic) error
CMake Error : error : generator : Visual Studio 15 2017 Win64
Still, the output of the in Windows compiler is weird and it does not show anything like "build completed with success". I hope it's fine.
The Matlab_HAS_CPP_API
flag seems to be fishy. It is enabled by default for Matlab & Matlab Runtime versions >= 9.4, but for some tests with Matlab Runtime 2018a (see https://github.com/robotology-dependencies/qpOASES/issues/12) I had to set it to manually set it to 0. I suspect that the issue is in CMake's upstream in FindMatlab, see https://github.com/robotology-dependencies/qpOASES/issues/12#issuecomment-493788107 for more info.
Related upstream (CMake) issue: https://gitlab.kitware.com/cmake/cmake/issues/19382 .
@RAR1989 @isorrentino Can you please check if on Windows the https://github.com/diegoferigo/blockfactory/tree/fix/windows branch compiles?
Compiling BlockFactory with MATLAB 2018a on Windows 10 Version 1803 with CMake 3.12.0 we got the following error: