robotology-playground / WBI-Toolbox

Simulink Toolbox for rapid prototyping of Whole Body Robot Controllers
2 stars 2 forks source link

OS X 10.9 - Compilation error #2

Closed andreadelprete closed 9 years ago

andreadelprete commented 10 years ago

I'm experiencing a problem when trying to run any simulink controller using the WBI-Toolbox. I installed CoDyCo-superbuild on Mac OS X 10.9 and I'm using Matlab 2013a. When I try to run (e.g.) controllerWithHandControl.slx (located in the folder torqueBalancing) I get the following error:

Making simulation target "WBCLibrary_sfun", ... 

/Applications/MATLAB_R2013a.app/bin/mex -c -O  -DMATLAB_MEX_FILE    -I/Applications/MATLAB_R2013a.app/stateflow/c/mex/include -I/Applications/MATLAB_R2013a.app/stateflow/c/debugger/include   WBCLibrary_sfun.c
In file included from WBCLibrary_sfun.c:3:
In file included from ./WBCLibrary_sfun.h:6:
In file included from /Applications/MATLAB_R2013a.app/stateflow/c/mex/include/sfc_sf.h:33:
In file included from /Applications/MATLAB_R2013a.app/simulink/include/mwmathutil.h:23:
/Applications/MATLAB_R2013a.app/extern/include/tmwtypes.h:819:9: error: unknown type
      name 'char16_t'
typedef char16_t CHAR16_T;
        ^
1 error generated.
    mex: compile of ' "WBCLibrary_sfun.c"' failed.
gmake: *** [WBCLibrary_sfun.o] Error 1

With the help of @francesco-romano I tried to solve it by modifying the Matlab's configuration file mexopts.sh so as to force the use of the c++11 standard library (because char16t has been introduced in c++11):

maci64)
#----------------------------------------------------------------------------
            # StorageVersion: 1.0
            # CkeyName: Clang
            # CkeyManufacturer: Apple
            # CkeyLanguage: C
            # CkeyVersion:
            # CkeyLinkerName:
            # CkeyLinkerVersion:
#CC='xcrun  -sdk macosx10.9  clang'
CC='clang'
## workaround clang defect temporarily use line below           SDKROOT='/Developer/SDKs/MacOSX10.6.sdk'
# compute SDK root on the fly
# target 10.7 
            MW_SDK_TEMP="find `xcode-select -print-path` -name MacOSX10.9.sdk"
            MW_SDKROOT=`$MW_SDK_TEMP`
            MACOSX_DEPLOYMENT_TARGET='10.9'
            ARCHS='x86_64'
            CFLAGS="-fno-common -arch $ARCHS -isysroot $MW_SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
            CFLAGS="$CFLAGS  -fexceptions"
            CLIBS="$MLIBS"
            COPTIMFLAGS='-O2 -DNDEBUG'
            CDEBUGFLAGS='-g'
#
#CLIBS="$CLIBS -lstdc++"
            CLIBS="$CLIBS"
            # C++keyName: Clang++
            # C++keyManufacturer: Apple
            # C++keyLanguage: C++
            # C++keyVersion:
            # C++keyLinkerName:
            # C++keyLinkerVersion:
            CXX='clang++'
            CXXFLAGS="-fno-common -fexceptions -arch $ARCHS -isysroot $MW_SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -std=c++11"
#            CXXLIBS="$MLIBS -lstdc++"
            CXXLIBS="$MLIBS"
            CXXOPTIMFLAGS='-O2 -DNDEBUG'
            CXXDEBUGFLAGS='-g'

Unfortunately, this had no effect on the error. To try and solve this problem @francesco-romano and I would like to gain an insight into the steps taken by simulink when one runs the model. In particular, why is simulink trying to compile WBCLibrary_sfun.c to generate a mex file? I thought all mex files were generated when compiling the WBI toolbox. Maybe @jeljaik can help us on this?

francesco-romano commented 10 years ago

This seems the same problem described here.

But.. reading again the issue, maybe I understood the problem. We are setting the option for C++, but simulink is trying to compile a .c file. @andreadelprete can you try to set CFLAGS="$CFLAGS -fexceptions -std=c11" ?

PS: I can't understand why my matlab works PPS: In Matlab2014 the mex configuration is different. Mathwork has been migrating to XML files instead of the old config one. But.. it is still the default one.

andreadelprete commented 10 years ago

I tried to set CFLAGS as you suggested, but nothing changed!

jeljaik commented 10 years ago

Hello guys,

Andrea, since I don't have Mac OS X myself I will at least try to explain why Matlab is however doing some sort of compilation (I will however check this on @iron76 's laptop). At the beginning of every simulation it does some compiling, but different from the MEX files compilation. If you check the MEX directory in $CODYCO_SUPERBUILD_DIR/build/install/mex you will notice that the libraries we compile are robotState (the main one for most of the blocks), minJerkGenerator, ySynchronizer, yRead and yWrite. There's no WBCLibrary_sfun. The Simulink Engine has a model compiler that converts the Simulink model into an executable besides doing some optimization process before actually running into the simulation cycle. I believe it's there that it's failing. You can find more on this here:

http://www.itu.dk/stud/speciale/segmentering/DittesBinfolder/bin/MATLAB6p5p1/help/toolbox/simulink/ug/how_simulink_works13.html

So, in the directory of any of your models after you run the simulation, this initial compilation process generates also a file xxxx_sfun.mexXXX.

jeljaik commented 10 years ago

I also noticed a backward compatibility problem since I've upgrade to Matlab R2014a and I just realized the library has to be exported for compatibility with earlier versions of Matlab. I'll be back to you guys soon. I'm testing things with @iron76 ... @francesco-romano You might not be experiencing the same issues due to the fact that also you are using my Matlab version.

jeljaik commented 10 years ago

I am not entirely sure if this can be related to your problem but I have saved the Toolbox compatible with earlier versions of Matlab and it is working for @iron76 . Can you try again please and let me know it it had any influence?

I would also like to throw some hints. @iron76 had a similar issue in the past and he solved it by commenting some stuff in the CMakeLists of the WBIToolbox. It might throw some hints: https://github.com/robotology/codyco/commit/8010141d0869e6c25f6254f63e7b048d1f4b2d98#commitcomment-6566181

francesco-romano commented 10 years ago

I add my R2012b mexopts.sh configuration file.

CC='clang'
            SDKROOT='/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk'
            MACOSX_DEPLOYMENT_TARGET='10.5'
            ARCHS='x86_64'
            CFLAGS="-fno-common -no-cpp-precomp -arch $ARCHS -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET -Dchar16_t=UINT16_T"
            CFLAGS="$CFLAGS  -fexceptions"
            CLIBS="$MLIBS"
            COPTIMFLAGS='-O2 -DNDEBUG'
            CDEBUGFLAGS='-g'
#
            CLIBS="$CLIBS -lc++" #CLIBS="$CLIBS -lstdc++"
            # C++keyName: GNU C++
            # C++keyManufacturer: GNU
            # C++keyLanguage: C++
            # C++keyVersion:
            # C++keyLinkerName:
            # C++keyLinkerVersion:
            CXX='clang++'
            CXXFLAGS="-fno-common -no-cpp-precomp -fexceptions -arch $ARCHS -isysroot $SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
            CXXLIBS="$MLIBS -lc++" #CXXLIBS="$MLIBS -lstdc++"
            CXXOPTIMFLAGS='-O2 -DNDEBUG'
            CXXDEBUGFLAGS='-g'
#
            # FortrankeyName: GNU Fortran
            # FortrankeyManufacturer: GNU
            # FortrankeyLanguage: Fortran
            # FortrankeyVersion: 
            # FortrankeyLinkerName: 
            # FortrankeyLinkerVersion:
            FC='gfortran'
            FFLAGS='-fexceptions -m64 -fbackslash'
            FC_LIBDIR=`$FC -print-file-name=libgfortran.dylib 2>&1 | sed -n '1s/\/*libgfortran\.dylib//p'`
            FC_LIBDIR2=`$FC -print-file-name=libgfortranbegin.a 2>&1 | sed -n '1s/\/*libgfortranbegin\.a//p'`
            FLIBS="$MLIBS -L$FC_LIBDIR -lgfortran -L$FC_LIBDIR2 -lgfortranbegin"
            FOPTIMFLAGS='-O'
            FDEBUGFLAGS='-g'
#
            LD="$CC"
            LDEXTENSION='.mexmaci64'
            LDFLAGS="-Wl,-twolevel_namespace -undefined error -arch $ARCHS -Wl,-syslibroot,$SDKROOT -mmacosx-version-min=$MACOSX_DEPLOYMENT_TARGET"
            LDFLAGS="$LDFLAGS -bundle -Wl,-exported_symbols_list,$TMW_ROOT/extern/lib/$Arch/$MAPFILE"
            LDOPTIMFLAGS='-O'
            LDDEBUGFLAGS='-g'
#
            POSTLINK_CMDS=':'
andreadelprete commented 10 years ago

Hi @jeljaik , sorry I'm late but I couldn't test your solution until today. I updated the codyco superbuild using make update-all but that didn't solve the problem. However, with @francesco-romano we found a VERY DIRTY fix, that is to add the following line in the mexopts.sh: CFLAGS="$CFLAGS -Dchar16_t=uint16_T" Of course, this is not a solution, but only a workaround. Moreover, now when I open the simulink model I get a bunch of warnings (I report here only the firsts, since they're all of the same kind):

Warning: Loading model 'WBCLibrary' generated with a newer  version (8.3) of Simulink 
  In general/private/openmdl at 13
  In general/private/openslx at 9
  In open at 159
  In uiopen at 196 
Warning: WBCLibrary.mdl, line 105: block_diagram does not have a parameter named
'CovEnableCumulative' 
  In general/private/openmdl at 13
  In general/private/openslx at 9
  In open at 159
  In uiopen at 196 
Warning: WBCLibrary.mdl, line 112: block_diagram does not have a parameter named
'CovSFcnEnable' 
  In general/private/openmdl at 13
  In general/private/openslx at 9
  In open at 159
  In uiopen at 196 
...
iron76 commented 10 years ago

I had a similar issue and I solved it by specifying a proper SDKROOT and a proper MACOSX_DEPLOYMENT_TARGET. In my case:

SDKROOT='/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk' MACOSX_DEPLOYMENT_TARGET='10.7'

However, these variables should be configured according to your system configuration. Francesco


Francesco Nori Robotics Brain Cognitive Science Department Cognitive Humanoids Lab Istituto Italiano di Tecnologia Via Morego, 30 16163 Genova, Italy http://people.liralab.it/iron/ francesco.nori@iit.itmailto:francesco.nori@iit.it

Phone: (+39) 010 71 781 420 Fax: +39 010 71 70 817

On Jun 23, 2014, at 11:49 AM, Andrea Del Prete wrote:

Hi @jeljaikhttps://github.com/jeljaik , sorry I'm late but I couldn't test your solution until today. I updated the codyco superbuild using make update-all but that didn't solve the problem. However, with @francesco-romanohttps://github.com/francesco-romano we found a VERY DIRTY fix, that is to add the following line in the mexopts.sh: CFLAGS="$CFLAGS -Dchar16_t=uint16_T" Of course, this is not a solution, but only a workaround. Moreover, now when I open the simulink model I get a bunch of warnings (I report here only the firsts, since they're all of the same kind):

Warning: Loading model 'WBCLibrary' generated with a newer version (8.3) of Simulink In general/private/openmdl at 13 In general/private/openslx at 9 In open at 159 In uiopen at 196 Warning: WBCLibrary.mdl, line 105: block_diagram does not have a parameter named 'CovEnableCumulative' In general/private/openmdl at 13 In general/private/openslx at 9 In open at 159 In uiopen at 196 Warning: WBCLibrary.mdl, line 112: block_diagram does not have a parameter named 'CovSFcnEnable' In general/private/openmdl at 13 In general/private/openslx at 9 In open at 159 In uiopen at 196 ...

— Reply to this email directly or view it on GitHubhttps://github.com/robotology-playground/WBI-Toolbox/issues/2#issuecomment-46824801.

jeljaik commented 9 years ago

Closing as solution has been described above and no feedback was ever given.