FAST S-Func MEXing process

Provide feedback, request enhancements, and get help with wind-turbine computer-aided engineering tools.

Moderators: Bonnie.Jonkman, Jason.Jonkman

Bonnie.Jonkman
Posts: 557
Joined: Thu Nov 10, 2005 10:51 am
Organization: Envision Energy USA
Location: Colorado
Location: Boulder, CO
Contact:

Re: FAST S-Func MEXing process

Postby Bonnie.Jonkman » Fri Jul 12, 2013 3:06 pm

Borchersen,

Thanks for posting your solution to getting the SFunc to work on 64-bit linux. I glanced at it briefly and made a quick fix to FASTGateway.f90 so that it should work on both 32 and 64-bit Windows.

To anyone else reading this,

You can download FAST_SFunc for 64-bit Windows (FAST v7.02.00d-bjj) here. I've also placed some new source files there so people can compile it themselves. Note that you will need to add /fpp to the compile options (for preprocessing FASTGateway.f90).


The quick fix involves just a few steps:
1) In FASTGateway.f90, add a statement to use ISO_C_BINDING and then set mwPointer to C_INTPTR_T
2) In make_FAST_SFunc.m, add the -compatibleArrayDims switch to the mex command
3) Change your options script to use the 64-bit compiler
Bonnie Jonkman

Envision Energy USA, 2016-
National Renewable Energy Laboratory, 2003-2016

Yunchuan.Li
Posts: 3
Joined: Wed Jun 25, 2014 6:57 pm
Organization: University of British Columbia
Location: Canada

Re: FAST S-Func MEXing process

Postby Yunchuan.Li » Thu Jun 26, 2014 11:53 am

Hi,
I am Yunchuan Li, currently an intern student at UBC. Now I face some problem in compiling the FAST_SFunc for 64 bit Matlab with the FASTGateway.f90 and make_FAST_SFunc.m downloaded from the online folder.
My compiler is Intel Fortran Composer XE 2013 SP1. I use Microsoft Visual Studio 2013 and 64 bit version of Matlab R2013a to compile the FAST_SFunc.
I set my intelf13msvs2012opts.bat file like this:

@echo off
rem INTELF13MSVS2012OPTS.BAT
rem
rem Compile and link options used for building MEX-files using the
rem Intel? Fortran Compiler 13.0 with the Microsoft? Visual Studio?
rem 2012 Professional Edition linker.
rem
rem StorageVersion: 1.0
rem FortrankeyFileName: INTELF13MSVS2012OPTS.BAT
rem FortrankeyName: Intel Visual Fortran
rem FortrankeyManufacturer: Intel
rem FortrankeyVersion: 13.0
rem FortrankeyLanguage: Fortran
rem FortrankeyLinkerName: Microsoft Visual Studio 2012
rem FortrankeyLinkerVersion: 11.0
rem
rem $Revision: 1.1.6.1 $ $Date: 2012/09/25 18:20:21 $
rem
rem ********************************************************************
rem General parameters
rem ********************************************************************
set MATLAB=E:\Program Files\MATLAB\R2013a
set IFORT_COMPILER13=C:\Program Files (x86)\Intel\Composer XE 2013 SP1
set VSINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio 12.0
set VCINSTALLDIR=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC
rem In this case, LINKERDIR is being used to specify the location of the SDK
set LINKERDIR=C:\Program Files (x86)\Windows Kits\8.0
set PATH=%IFORT_COMPILER13%\Bin\Intel64;%VCINSTALLDIR%\bin\amd64;%LINKERDIR%\bin\x64;%VCINSTALLDIR%\BIN;%VSINSTALLDIR%\Common7\Tools;%VSINSTALLDIR%\Common7\Tools\bin;%MATLAB_BIN%;%PATH%
set INCLUDE=%IFORT_COMPILER13%\compiler\Include;%LINKERDIR%\include\um;%LINKERDIR%\include\shared;%LINKERDIR%\include\winrt;%VCINSTALLDIR%\ATLMFC\INCLUDE;%VCINSTALLDIR%\INCLUDE;%VCINSTALLDIR%\VCPackages;%INCLUDE%
set LIB=%IFORT_COMPILER13%\compiler\Lib\Intel64;%LINKERDIR%\LIB\win8\um\x64;%VCINSTALLDIR%\LIB\amd64;%VCINSTALLDIR%\ATLMFC\LIB\amd64;%MATLAB%\extern\lib\win64;%LIB%

set MW_TARGET_ARCH=win64

rem ********************************************************************
rem Compiler parameters
rem ********************************************************************
set COMPILER=ifort
set COMPFLAGS= /fpp /Qprec /assume:byterecl /traceback /real_size:64 /Qzero /Qsave "/I%MATLAB%/extern/include" -c -nologo -DMATLAB_MEX_FILE /MD /fp:source
set OPTIMFLAGS=/O2 /DNDEBUG
set DEBUGFLAGS=/Z7
set NAME_OBJECT=/Fo

rem ********************************************************************
rem Linker parameters
rem ********************************************************************
set LIBLOC=E:\Program Files\MATLAB\R2013a\extern\lib\win64\microsoft
set LINKER=link
set LINKFLAGS=/dll /export:MEXFUNCTION /LIBPATH:"%LIBLOC%" libmx.lib libmex.lib libmat.lib /implib:"%LIB_NAME%.x" /MAP:"%OUTDIR%%MEX_NAME%%MEX_EXT%.map" /NOLOGO /manifest /INCREMENTAL:NO
set LINKOPTIMFLAGS=
set LINKDEBUGFLAGS=/debug /PDB:"%OUTDIR%%MEX_NAME%%MEX_EXT%.pdb"
set LINK_FILE=
set LINK_LIB=
set NAME_OUTPUT=/out:"%OUTDIR%%MEX_NAME%%MEX_EXT%"
set RSP_FILE_INDICATOR=@

rem ********************************************************************
rem Resource compiler parameters
rem ********************************************************************
set RC_COMPILER=rc /fo "%OUTDIR%mexversion.res"
set RC_LINKER=

set POSTLINK_CMDS=del "%LIB_NAME%.x" "%LIB_NAME%.exp"
set POSTLINK_CMDS1=mt -outputresource:"%OUTDIR%%MEX_NAME%%MEX_EXT%";2 -manifest "%OUTDIR%%MEX_NAME%%MEX_EXT%.manifest"
set POSTLINK_CMDS2=del "%OUTDIR%%MEX_NAME%%MEX_EXT%.manifest"
set POSTLINK_CMDS3=del "%OUTDIR%%MEX_NAME%%MEX_EXT%.map"


But when I try to compile the FAST_SFunc, it results in errors:



--> link /out:"FAST_SFunc.mexw64" /dll /export:MEXFUNCTION /LIBPATH:"E:\Program Files\MATLAB\R2013a\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib /implib:"C:\Users\CEL\AppData\Local\Temp\mex_kBGAR3\templib.x" /MAP:"FAST_SFunc.mexw64.map" /NOLOGO /manifest /INCREMENTAL:NO @C:\Users\CEL\AppData\Local\Temp\mex_kBGAR3\mex_tmp.rsp

Creating library C:\Users\CEL\AppData\Local\Temp\mex_kBGAR3\templib.x and object C:\Users\CEL\AppData\Local\Temp\mex_kBGAR3\templib.exp
MSVCRT.lib(crtdll.obj) : error LNK2019: unresolved external symbol __imp_EncodePointer referenced in function pre_c_init
MSVCRT.lib(atonexit.obj) : error LNK2001: unresolved external symbol __imp_EncodePointer
MSVCRT.lib(crtdll.obj) : error LNK2019: unresolved external symbol __imp_DecodePointer referenced in function _CRT_INIT
MSVCRT.lib(atonexit.obj) : error LNK2001: unresolved external symbol __imp_DecodePointer
MSVCRT.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp_QueryPerformanceCounter referenced in function __security_init_cookie
MSVCRT.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp_GetCurrentProcessId referenced in function __security_init_cookie
MSVCRT.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp_GetCurrentThreadId referenced in function __security_init_cookie
MSVCRT.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp_GetSystemTimeAsFileTime referenced in function __security_init_cookie
MSVCRT.lib(dllmain.obj) : error LNK2019: unresolved external symbol __imp_DisableThreadLibraryCalls referenced in function DllMain
FAST_SFunc.mexw64 : fatal error LNK1120: 7 unresolved externals

E:\PROGRA~1\MATLAB\R2013A\BIN\MEX.PL: Error: Link of 'FAST_SFunc.mexw64' failed.

Error using mex (line 206)
Unable to complete successfully.

Error in make_FAST_SFunc (line 69)
mex('-v' , ... %verbose

>>

When I did this on 32 bit Version of Matlab and try to comile FAST_SFunc for 32bit Matlab, it compiles smoothly without any error.
I don't know what the link error is and really exhausted of ideas on how to fix the problem.
Does any body have ideas on how to solve this problem.
Thank you!
Yunchuan

Bonnie.Jonkman
Posts: 557
Joined: Thu Nov 10, 2005 10:51 am
Organization: Envision Energy USA
Location: Colorado
Location: Boulder, CO
Contact:

Re: FAST S-Func MEXing process

Postby Bonnie.Jonkman » Wed Jul 09, 2014 1:20 pm

I have not seen this error before, but it looks like it's using the wrong version of the MSVCRT.lib file. That could mean that you've got a path issue where it's finding the 32-bit version of the MSVCRT.lib file instead of the 64-bit version. Or perhaps you've got a dynamic version instead of a static version (try removing /MD from COMPFLAGS and see if that helps).

Good luck!
Bonnie Jonkman

Envision Energy USA, 2016-
National Renewable Energy Laboratory, 2003-2016

Yunchuan.Li
Posts: 3
Joined: Wed Jun 25, 2014 6:57 pm
Organization: University of British Columbia
Location: Canada

Re: FAST S-Func MEXing process

Postby Yunchuan.Li » Thu Jul 10, 2014 5:43 pm

Bonnie.Jonkman wrote:I have not seen this error before, but it looks like it's using the wrong version of the MSVCRT.lib file. That could mean that you've got a path issue where it's finding the 32-bit version of the MSVCRT.lib file instead of the 64-bit version. Or perhaps you've got a dynamic version instead of a static version (try removing /MD from COMPFLAGS and see if that helps).

Good luck!




Hi Bonnie,
Thank you for your help!

First of all, reached the same conclusion that the linker is finding the 32bit version of the lib file. Since even though we do not set linker direction when compiling 32 bit SFunction, it compiles without any error. But when I set the linker direction to blank when compiling 64 bit SFunction, it result in the same error.

Secondly, we tried your suggestion to remove /MD from COMPFLAG, it resulted in another error:

LIBCMT.lib(wgetcwd.obj) : error LNK2001: unresolved external symbol __imp_GetFullPathNameW
LIBCMT.lib(read.obj) : error LNK2019: unresolved external symbol __imp_ReadConsoleW referenced in function _read_nolock
libirc.lib(tbk_backtrace.obj) : error LNK2019: unresolved external symbol __imp_VirtualQuery referenced in function tbk_getModuleName
FAST_SFunc.mexw64 : fatal error LNK1120: 137 unresolved externals

E:\PROGRA~1\MATLAB\R2013A\BIN\MEX.PL: Error: Link of 'FAST_SFunc.mexw64' failed.

Error using mex (line 206)
Unable to complete successfully.

Error in make_FAST_SFunc (line 69)
mex('-v'


(There are actually more errors, I just cut theend of the report ).
Anyone has some ideas about this error?

Again thank you for your help!
Yunchuan Li

Bonnie.Jonkman
Posts: 557
Joined: Thu Nov 10, 2005 10:51 am
Organization: Envision Energy USA
Location: Colorado
Location: Boulder, CO
Contact:

Re: FAST S-Func MEXing process

Postby Bonnie.Jonkman » Thu Jul 10, 2014 9:05 pm

Could you post the first error(s)? They are more helpful than the last ones.

I'm not sure what "linker direction" is. Do you mean "LINKERDIR"? LINKERDIR is just the directory (folder) where the linker is located, though in your case, it says it's where SDK (software development kit) is located.

Also, you should try to verify that the %PATH%, %INCLUDE% and %LIB% environment variables in your batch file are the same as the values you get when you echo them in the Intel 64 Visual Studio command prompt window. The only differences should be that the variables in the Intel 64 VS window won't list the folders that contain %MATLAB%. For instance, the %LIB% variable in your batch file looks like it's set like this:

Code: Select all

LIB=
C:\Program Files (x86)\Intel\Composer XE 2013 SP1\compiler\Lib\Intel64;
C:\Program Files (x86)\Windows Kits\8.0\LIB\win8\um\x64;
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\LIB\amd64;
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\ATLMFC\LIB\amd64;
E:\Program Files\MATLAB\R2013a\extern\lib\win64;
(most computers don't have %LIB% defined outside the compiler window; if you do, there will be more folders listed under "LIB"; also, I put line breaks between the folder names, but your variable will be one long messy line).
When you type

Code: Select all

echo %LIB%
in the Intel 64 Visual Studio command prompt window, does it show these folders:

Code: Select all

C:\Program Files (x86)\Intel\Composer XE 2013 SP1\compiler\Lib\Intel64;
C:\Program Files (x86)\Windows Kits\8.0\LIB\win8\um\x64;
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\LIB\amd64;
C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\ATLMFC\LIB\amd64;
If they aren't the same or there are more in the Intel 64 VS window than in the batch script, that will be a problem. (If you need help finding the Inte 64 Visual Studio command prompt window, see Figure 2 in this document: http://wind.nrel.gov/public/bjonkman/De ... ctions.pdf)
Bonnie Jonkman

Envision Energy USA, 2016-
National Renewable Energy Laboratory, 2003-2016

Yunchuan.Li
Posts: 3
Joined: Wed Jun 25, 2014 6:57 pm
Organization: University of British Columbia
Location: Canada

Re: FAST S-Func MEXing process

Postby Yunchuan.Li » Mon Jul 14, 2014 4:10 pm

Hi Bonnie,
Thank you for your reply.
1.
The first errors are like this

Code: Select all

--> ifort   /fpp /Qprec /assume:byterecl /traceback /real_size:64 /Qzero /Qsave "/IE:\Program Files\MATLAB\R2013a/extern/include" -c -nologo -DMATLAB_MEX_FILE  /fp:source /MD /FoC:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\FASTGateway64.obj /O2 /DNDEBUG -DMX_COMPAT_32 "E:\Control of Wind Turbines\FAST_SFunc Compiling\FAST\Simulink\Source\FASTGateway64.f90"
 
    Contents of C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\mex_tmp.rsp:
  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\DoubPrec.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\SysMatlab.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\NWTC_IO.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\NWTC_Num.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\NWTC_Aero.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\ModMesh.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\NWTC_Library.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\SharedInflowDefs.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\HHWind.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\FFWind.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\HAWCWind.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\FDWind.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\CTWind.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\UserWind.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\InflowWindMod.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\SharedTypes.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\AeroMods.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\GenSubs.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\AeroSubs.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\AeroDyn.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\FAST_Mods.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\Noise.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\fftpack.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\FFTMod.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\HydroCalc.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\AeroCalc.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\FAST_IO.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\FAST.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\PitchCntrl_ACH.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\SetVersion.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\UserSubs.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\UserVSCont_KP.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\FASTSimulink.obj  C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\FASTGateway64.obj
 
 
--> link /out:"FAST_SFunc.mexw64" /dll /export:MEXFUNCTION /LIBPATH:"E:\Program Files\MATLAB\R2013a\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib /implib:"C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\templib.x" /MAP:"FAST_SFunc.mexw64.map" /NOLOGO /manifest /INCREMENTAL:NO  @C:\USERS\CEL\APPDATA\LOCAL\TEMP\MEX_GT~1\MEX_TMP.RSP   
 
   Creating library C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\templib.x and object C:\Users\CEL\AppData\Local\Temp\mex_gtzs6q\templib.exp
MSVCRT.lib(crtdll.obj) : error LNK2019: unresolved external symbol __imp_EncodePointer referenced in function pre_c_init
MSVCRT.lib(atonexit.obj) : error LNK2001: unresolved external symbol __imp_EncodePointer
MSVCRT.lib(crtdll.obj) : error LNK2019: unresolved external symbol __imp_DecodePointer referenced in function _CRT_INIT
MSVCRT.lib(atonexit.obj) : error LNK2001: unresolved external symbol __imp_DecodePointer
MSVCRT.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp_QueryPerformanceCounter referenced in function __security_init_cookie
MSVCRT.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp_GetCurrentProcessId referenced in function __security_init_cookie
MSVCRT.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp_GetCurrentThreadId referenced in function __security_init_cookie
MSVCRT.lib(gs_support.obj) : error LNK2019: unresolved external symbol __imp_GetSystemTimeAsFileTime referenced in function __security_init_cookie
MSVCRT.lib(dllmain.obj) : error LNK2019: unresolved external symbol __imp_DisableThreadLibraryCalls referenced in function DllMain
FAST_SFunc.mexw64 : fatal error LNK1120: 7 unresolved externals
 
  E:\PROGRA~1\MATLAB\R2013A\BIN\MEX.PL: Error: Link of 'FAST_SFunc.mexw64' failed.
 
Error using mex (line 206)
Unable to complete successfully.

Error in make_FAST_SFunc (line 69)
mex('-v'
, ... %verbose
 

(I did NOT remove the "/MD" in COMFLAGS)
If I remove this flag, the error would be

Code: Select all

LIBCMT.lib(wgetcwd.obj) : error LNK2001: unresolved external symbol __imp_GetFullPathNameW
LIBCMT.lib(read.obj) : error LNK2019: unresolved external symbol __imp_ReadConsoleW referenced in function _read_nolock
libirc.lib(tbk_backtrace.obj) : error LNK2019: unresolved external symbol __imp_VirtualQuery referenced in function tbk_getModuleName
FAST_SFunc.mexw64 : fatal error LNK1120: 137 unresolved externals

E:\PROGRA~1\MATLAB\R2013A\BIN\MEX.PL: Error: Link of 'FAST_SFunc.mexw64' failed.


(There are hundreds of errors, I just pasted a part of them)

2. I checked the LIB, INCLUDE and PATH from the Intel 64 Visual Studio command prompt window. Originally they are different from those in the batch file. So I changed them and set the identical with those in the batch file, however, it did not help. Actually it shows the same error as I previously described.

And sorry for the ambiguous "linker direction", I just mean "LINKERDIR".
Is there anything else I can check for the compiling process?
Thank you!

Yunchuan Li

Michael.Shafer
Posts: 2
Joined: Thu Jul 24, 2014 11:49 am
Organization: Northern Arizona University
Location: Arizona

Re: FAST S-Func MEXing process

Postby Michael.Shafer » Mon Jul 28, 2014 1:44 pm

Bonnie,
I am a new FAST user and I am trying to get it up and running within Simulink. I have a 64-bit Windows machine and I have been attempting to use the 64-bit SFunc you posted in this post from last year:

Borchersen,

Thanks for posting your solution to getting the SFunc to work on 64-bit linux. I glanced at it briefly and made a quick fix to FASTGateway.f90 so that it should work on both 32 and 64-bit Windows.

To anyone else reading this,

You can download FAST_SFunc for 64-bit Windows (FAST v7.02.00d-bjj) here. I've also placed some new source files there so people can compile it themselves. Note that you will need to add /fpp to the compile options (for preprocessing FASTGateway.f90).



I downloaded FAST_SFunc.mexw64, saved it to the location where the old 32-bit version was located (I moved that original file elsewhere), and added the location of this new 64-bit file to MATLAB's path. When I attempt to run the sample simulink model provided with FASTv7, OpenLoop.mdl, MATLAB consistently crashes. Do you have any idea why this might be happening?

FYI, prior to finding your FAST_SFunc.mexw64 file, I had installed a 32-bit version of MATLAB and had similar results (crashing). I thought it might have had something to do with the fact that I was running on a 64-bit machine, which is why I did some more searching and found your post. Please help if you can. Thanks.

-Michael

Michael.Shafer
Posts: 2
Joined: Thu Jul 24, 2014 11:49 am
Organization: Northern Arizona University
Location: Arizona

Re: FAST S-Func MEXing process

Postby Michael.Shafer » Mon Jul 28, 2014 3:29 pm

This is a reply to my own post from July 28, 2014.

I was able to get the Simulation to run. I have both the 32-bit and 64-bit versions of Matlab on my machine. It seems as though the 32-bit version was opening despite me selecting (what I thought was) the 64-bit version. When I finally realized what the problem was and opened the correct version, the simulation seemed to move pass point where it was previously crashing, but then would throw an error about needed to run Read_FAST_Input.m prior to starting the simulation. This isn't mentioned in the FAST User's Guide. When I ran that m-function and then ran the simulation, it seemed to run without issue.

-Michael


Return to “Computer-Aided Engineering Software Tools”

Who is online

Users browsing this forum: No registered users and 1 guest