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

Ubuntu, S-Function, mex, error message #387

Closed
Balazs-G opened this issue Feb 9, 2020 · 26 comments
Closed

Ubuntu, S-Function, mex, error message #387

Balazs-G opened this issue Feb 9, 2020 · 26 comments

Comments

@Balazs-G
Copy link

Balazs-G commented Feb 9, 2020

Dear Developer,

I would like to run the OpenLoop Simulink model, but unfortunately I've stuck at creating the S-Function. OpenFAST is working seamless in terminal. Several r-tests has been performed, and the new simulation results fulfill the expectations, too. But when I run the 'create_FAST_SFunc.m', I got the error message (see below). MATLAB r2017b and MATLAB r2019b warned on different gcc versions ( both missing in my case), but resulted same undefined references
Can be the problem caused by the missing gcc version? I would like to try other ways before installing a gcc version not supported by Canonical.

Thank you for your great work and persistent efforts to support FAST!
Balazs

MATLAB error:

Warning: You are using gcc version '5.4.0'. The version of gcc is not supported. The version >currently supported with MEX is '6.3.x'. For a list of
currently supported compilers see: https://www.mathworks.com/support/compilers/current_release.
Error using mex
/home/balazs/OpenFAST/install/lib/libopenfastlib.a(FAST_Library.f90.o): In function FAST_OpFM_Step': FAST_Library.f90:(.text+0xb6): undefined reference to __fast_subs_MOD_fast_solution_t'
FAST_Library.f90:(.text+0x108): undefined reference to _gfortran_string_len_trim' FAST_Library.f90:(.text+0x147): undefined reference to _gfortran_concat_string'
FAST_Library.f90:(.text+0x18c): undefined reference to _gfortran_concat_string' FAST_Library.f90:(.text+0x2f1): undefined reference to _gfortran_concat_string'
FAST_Library.f90:(.text+0x38c): undefined reference to __supercontroller_MOD_sc_setoutputs' FAST_Library.f90:(.text+0x3fa): undefined reference to __supercontroller_MOD_sc_setinputs'
/home/balazs/OpenFAST/install/lib/libopenfastlib.a(FAST_Library.f90.o): In function FAST_OpFM_Restart': FAST_Library.f90:(.text+0x85b): undefined reference to __nwtc_library_MOD_nwtc_init'
FAST_Library.f90:(.text+0x896): undefined reference to `_gfortran_string_index'
.
.
.
..

FAST_Library.f90:(.text+0xaba13): undefined reference to _gfortran_runtime_error_at' FAST_Library.f90:(.text+0xaba1f): undefined reference to _gfortran_os_error'
collect2: error: ld returned 1 exit status

Error in create_FAST_SFunc (line 71)
mex('-largeArrayDims', ...

MATLAB environment
pwd
'/home/bala/OpenFAST/glue-codes/simulink/src'

The final form of mex command:
mex('-largeArrayDims', ...
'-L/home/bala/OpenFAST/install/lib', ...
'-lopenfastlib', ...
'-I/home/bala/OpenFAST/install/include', ...
'-I/home/bala/OpenFAST/modules/supercontroller/src', ...
'-I/home/bala/OpenFAST/modules/openfoam/src', ...
'-outdir', '.', ...
'COMPFLAGS=$COMPFLAGS -MT -D', ...
'S_FUNCTION_NAME=FAST_SFunc', ...
'-output', 'FAST_SFunc', ...
'FAST_SFunc.c');

OpenFAST Version


OpenFAST

Copyright (C) National Renewable Energy Laboratory
Copyright (C) Envision Energy USA LTD

This program is licensed under Apache License Version 2.0 and comes with ABSOLUTELY NO WARRANTY.
See the "LICENSE" file distributed with this software for details.


OpenFAST-v2.2.0
Compile Info:

  • Architecture: 64 bit
  • Precision: double
  • Date: Jan 3 2020
  • Time: 23:27:19
    Execution Info:
  • Date: 02/09/2020
  • Time: 11:31:30+0100

System Information:

@bjonkman
Copy link
Contributor

The short answer is, yes, the incompatible gcc version is likely causing the errors you see.

Each version of Matlab has a compilers that it is set up to work with. You may be able to get around this by modifying the relevant files in the <MATLAB_ROOT>/bin/<os>/mexopts directory, making sure the paths and libraries are set for the version you are using. If you choose to modify these files, you will also likely have to remove the -MT option from the mex command in create_FAST_SFunc.m so that it is not trying to link with static libraries created with a different compiler. And if you remove the -MT, you may have to add the library paths to the MATLAB path so it can find the dynamic libraries when you run the mex function.

I would also run mex -setup again after changing the files in the mexopts directory, though that might not be necessary.

@Balazs-G
Copy link
Author

I've just got a proper (supported) combination of MATLAB (2017a), gcc 4.9 and Ubuntu 16.04.

I wanted to compile openFAST with the current version of gcc, but unfortunately cmake resulted an error message: SIMULINK with GNU is not supported.

Should I install Windows and Visual Studio in order to be able to connect openFAST to Simulink?
Is there an earlier version of openFAST suitable to work with Simulink under Ubuntu?

Thank you!
Balazs

@bjonkman
Copy link
Contributor

It looks like the Sys*.f90 file for that combination hasn't been updated in OpenFAST. Basically, you would need to replace the write statements in the SysGnuLinux.f90 file with calls to the Matlab mex print library. I've taken a quick attempt at doing that for you in this branch: https://github.com/bjonkman/openfast/tree/f/SimulinkGNUlinux Let us know if that works.

@Balazs-G
Copy link
Author

Dear Bonnie,

thank you for the useful support! Using your proposed branch the cmake and the make command resulted no errors. However the 'install' folder was missing. I created manually the folder and tried to find and copy all of the missing files into it. Then I was able to run create_FAST_SFunc.m in Matlab 2017a without any warning or error message and got the FAST_SFunc.mexa64. I tried to run the openLoop.mdl with AWT_YFix_WSt.fst , but unfortunately it failed with the following error message:

Error while obtaining sizes from MEX S-function 'FAST_SFunc' in 'OpenLoop/FAST Nonlinear Wind Turbine/S-Function'.
Caused by:
Invalid MEX-file '/home/bala/openfast-SimulinkGNUlinux/simulink/FAST_SFunc.mexa64': libopenfastlib.so: cannot open shared object file: No such file or directory.
Component:Simulink | Category:Block error

The command line version of openFast successfully simulated the same AWT_YFix_WSt.fst

Unfortunately the error message isn't too informative for me. I would be pleased if you could send me some hint to be able to identify the reasons for this error.

@bjonkman
Copy link
Contributor

I would guess that Matlab cannot find the libopenfastlib.so file. Check to see where that file is located, and either modify the Matlab path to find it, or move the file somewhere on the Matlab search path.

@Balazs-G
Copy link
Author

I forgot to mention, that this was my first and only idea to solve the problem...

@bjonkman
Copy link
Contributor

Did you create a file called libopenfastlib.so with a 64-bit compiler?

@Balazs-G
Copy link
Author

Balazs-G commented Feb 17, 2020

yes, I tried to follow the instructions in the online documentation (2.2. Compile from source)
cmake .. -BUILD_OPENFAST_SIMULINK_API=ON -DBUILD_SHARED_LIBS=ON
make

@bjonkman
Copy link
Contributor

If you type which libopenfastlib.so in the Matlab command window, does it find the file? If so, can you check which dependencies are in that libopenfastlib.so library and make sure all of those files are also in the MATLAB path? E.g., if libopenfastlib.so depends on some GNU Fortran libraries, they would also need to be on the Matlab path.

@rafmudaf may have some ideas on which dynamic library dependencies are generated with the OpenFAST cmake build process.

@Balazs-G
Copy link
Author

which libopenfastlib.so results the proper path to the file
there are 25 *.so file in the same folder (libaerodyn14lib.so, libaerodynlib.so, etc)
As I mentioned the Install folder wasn't created during the compilation. I tried to find all of the files needed to run the create_FAST_SFunc.m. Perhaps still missing one?

@bjonkman
Copy link
Contributor

Perhaps. You could also try building with -DBUILD_SHARED_LIBS=OFF

@Balazs-G
Copy link
Author

OK, I'll report the result. Have a nice day and thank you for the support!

@Balazs-G
Copy link
Author

Balazs-G commented Feb 18, 2020

Thank you for the support! Original problem seems to be solved: the LD_LIBRARY_PATH environment variable has to include the install/lib folder.
Conclusion:

  • Ubuntu 16.04, gcc 4.9, g++ 4.9, MATLAB2017a
  • SimulinkGNUlinux branch by bjonkman
  • Online documentation (https://openfast.readthedocs.io/en/master/) Chapter 2.2. Compile from source
  • cmake .. -BUILD_OPENFAST_SIMULINK_API=ON -DBUILD_SHARED_LIBS=ON
  • make
  • manual copy of the required files into the /install folder (/lib: required /bin: ?, /include: ?)
  • command in terminal window:
    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/openfast/install/lib
    export LD_PRELOAD=$LD_PRELOAD:/path/to/liblapack.so (avoiding the usage of MKL Lapack library installed with Matlab)
  • run matlab
  • run create_FAST_SFunc.m in matlab window

This resulted a FAST_SFunc.mexa64 file in the /openfast/glue-codes/simulink/src folder. The Run_OpenLoop.m now begins to run without missing files and regular messages of the openFAST simulation can be seen in the matlab command window.

Thank you for your support!

@kumaraeedara
Copy link

Dear all,
I am using OpenFASTv2.2.0 on Windows07. I was able to successfully run simulation of WP1.5MW turbine in OpenFAST (using .exe) but facing issues in running the same through simulink.

While trying to run the simulation using simulink, I receive the following error:

Error reported by S-function 'FAST_SFunc' in 'OpenLoop/FAST Nonlinear Wind Turbine/S-Function':
FAST_InitializeAll:AD_Init:ReadInputFiles:ReadPrimaryFile:Invalid numerical input for file
"E:\OpenFAST\WP1500kW\AeroDyn15_Dynin.dat" occurred while trying to read AirDens.

My understanding is that the error is because of the extra "CavitCheck" added in the AeroDynV15.
Please note that I am using the files "FAST_SFunc.mexw64" and "FAST_Library_x64.lib" that are available with FASTv8 itself. Could this be causing the issue? If yes, is there a pre-compliled "mex" and "lib" files available with OpenFAST package or do I need to compile it separately. (Also, any document on how to do it in windows). Thanks.

Regards,
Kumara

@jjonkman
Copy link
Collaborator

Dear Kumara,

It sounds like you are using the OpenFAST v.2.2.0 executable, but the FAST v8 S-Function (FAST_SFunc.mexw64) and library (FAST_Library_x64.lib). Running the executable is independent from running the S-Function with the library.

The FAST S-Function and FAST Library must be recompiled with OpenFAST. These are not currently supplied in the compiled OpenFAST binaries. (Although perhaps @rafmudaf could provide those.)

On Windows, I would recommend compiling using Visual Studio with Intel Fortran. To build the OpenFAST Library, Open up the Visual Studio solution, select the Release_MATLAB configuration for the x64 platform and build. (If you do not have MATLAB 2018a installed, you'll have to change the path to MATLAB in the OpenFAST-Simulink project's Configuration Properties -> Linker -> Input window in the Additional Dependencies field.) To build the FAST S-Function, run the MATLAB create_FAST_SFunc.m script located in the glue-codes\simulink\src directory.

Best regards,

@kumaraeedara
Copy link

kumaraeedara commented Mar 21, 2020

Dear JJonkman,
Thanks for your response. I could resolve the issue following the steps you have suggested. I have made a doc for quick reference of the procedure with pictures and attached here. (May be useful to someone ).
OpenFAST_Simulink.pdf

After preparing this I found there is another useful link discussion here:
#268

@jjonkman
Copy link
Collaborator

Thanks for sharing!

@whisperingkahuna
Copy link

whisperingkahuna commented Jun 15, 2020

Hi team,
I want to use openfast for Matlab and I am trying to generate MEX files that need to run OpenFAST (latest release) through MATLAB (Simulink).
I followed the suggestions in this thread and Now I am getting this fatal error

image

Bin folder looks like this

image

I am using;
VS 2017 version 15.9.23
Intell parallel studio XE 2020
Matlab 2020a

mex -setup
MEX configured to use 'Intel Parallel Studio XE 2020 with Microsoft Visual Studio 2017 (C)' for C language compilation.

To choose a different C compiler, select one from the following:
Intel Parallel Studio XE 2020 with Microsoft Visual Studio 2017 (C) mex -setup:C:\Users******\AppData\Roaming\MathWorks\MATLAB\R2020a\mex_C_win64.xml C
Microsoft Visual C++ 2017 (C) mex -setup:'C:\Program Files\MATLAB\R2020a\bin\win64\mexopts\msvc2017.xml' C

@whisperingkahuna
Copy link

update
i repeat the procedure again to see if the error persists and i got rid of the fatal error, but the warnings are still there

image

Upon executing create_FAST_SFunc.m, I get this error

create_FAST_SFunc


Creating ../../../build/bin\FAST_SFunc.mexw64

Error using mex
MEX cannot find library 'OpenFAST-Simulink_x64', specified with the -l option.
MEX searched for a file with one of the following names:
libOpenFAST-Simulink_x64.lib
OpenFAST-Simulink_x64.lib
Verify the library name is correct. If the library is not
on the existing path, specify the path with the -L option.

Error in create_FAST_SFunc (line 60)
mex('-largeArrayDims', ...

@bjonkman
Copy link
Contributor

Those warnings are normal.

Did the Visual Studio build process actually generate the OpenFAST-Simulink_x64.dll file in the <openfast>\build\src folder? If so, is there also an OpenFAST-Simulink_x64.lib file there? That .lib file is what mex will use in the linking process.

Are you running create_FAST_SFunc.m from the folder where that file is located? The directories are specified relative to <openfast>\glue-codes\simulink\src, so that could also cause an issue.

@whisperingkahuna
Copy link

Thank you for your response @bjonkman

The visual studio build process (Release_MATLAB, x64) did not generate these files ( OpenFAST-Simulink_x64.dll, OpenFAST-Simulink_x64.lib).

I am running the create_FAST_SFunc.m from the folder and the required directories are set accordingly in the Matlab. I think since the above-mentioned files are not successfully generated I am getting this error.

Regards,

@bjonkman
Copy link
Contributor

I looked a little closer at your second screen shot. In that case, you seem to be building the OpenFAST executable instead of the OpenFAST-Simulink library. Make sure your configuration manager says "Release_Matlab" and "x64" before building. I would also check that you've specified the location of the MATLAB mex library correctly (right click on the OpenFAST-Simulink project, then select Properties. Make sure the Configuration says Release_Matlab and Platform says x64. Then select Configuration Properties->Linker->Input->Additional Dependencies . You will need quotation marks around that path because there is a space in it.
image

@whisperingkahuna
Copy link

Thank you for your help in resolving this issue. I was doing everything as you mentioned except for the quotation marks around the path. Now, I am able to generate the required Simulink files.

Best Regards,

@saeidfn
Copy link

saeidfn commented Aug 22, 2020

Dear @bjonkman
By your explanation, I could manage to build "FAST_SFunc.mexw64". For the next step, run an example, would you help me how to use that file and run an input file such as "Input.fst" with Matlab Simulink??

@jjonkman
Copy link
Collaborator

Dear @saeidfn,

Documentation for running FAST v8 interfaced to MATLAB/Simulink is included in the FAST v8 ReadMe file, see: https://drive.google.com/file/d/17LDwMnCVmLfbRWSaVFxxqphVrtawMwlj/view?usp=sharing. The instructions should be basically the same for OpenFAST.

Best regards,

@rafmudaf
Copy link
Collaborator

I'm working on establishing a path for distributing the OpenFAST Library compiled for Simulink integration along with the other executables we regularly share for each release. I've added a file included in the last Release called openfastlib_simulink.dll. Is someone able to test the attached library? This is the OpenFAST Library that should be linked in the mex-function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants