-
Notifications
You must be signed in to change notification settings - Fork 468
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
Setting up the JSBSim interface to Matlab on Windows #491
Comments
Dear Prof. De Marco, Thanks a lot for the detailed instruction. I followed all the steps and still arrived at some fatal errors: JSBSimInterface.obj : error LNK2019: unresolved external symbol "public: __cdecl JSBSim::FGFDMExec::FGFDMExec(class JSBSim::FGPropertyManager *,class std::shared_ptr<unsigned int>)"
(??0FGFDMExec@JSBSim@@QEAA@PEAVFGPropertyManager@1@V?$shared_ptr@I@std@@@Z) referenced in function "public: __cdecl JSBSimInterface::JSBSimInterface(double)" (??0JSBSimInterface@@QEAA@N@Z)
JSBSimInterface.obj : error LNK2019: unresolved external symbol "public: class std::shared_ptr<class JSBSim::FGAccelerations> __cdecl JSBSim::FGFDMExec::GetAccelerations(void)const "
(?GetAccelerations@FGFDMExec@JSBSim@@QEBA?AV?$shared_ptr@VFGAccelerations@JSBSim@@@std@@XZ) referenced in function "public: __cdecl JSBSimInterface::JSBSimInterface(double)"
(??0JSBSimInterface@@QEAA@N@Z)
JSBSimInterface.obj : error LNK2019: unresolved external symbol "public: class std::shared_ptr<class JSBSim::FGFCS> __cdecl JSBSim::FGFDMExec::GetFCS(void)const "
(?GetFCS@FGFDMExec@JSBSim@@QEBA?AV?$shared_ptr@VFGFCS@JSBSim@@@std@@XZ) referenced in function "public: __cdecl JSBSimInterface::JSBSimInterface(double)" (??0JSBSimInterface@@QEAA@N@Z)
JSBSimInterface.obj : error LNK2019: unresolved external symbol "public: class std::shared_ptr<class JSBSim::FGPropulsion> __cdecl JSBSim::FGFDMExec::GetPropulsion(void)const "
(?GetPropulsion@FGFDMExec@JSBSim@@QEBA?AV?$shared_ptr@VFGPropulsion@JSBSim@@@std@@XZ) referenced in function "public: __cdecl JSBSimInterface::JSBSimInterface(double)"
(??0JSBSimInterface@@QEAA@N@Z)
JSBSimInterface.obj : error LNK2019: unresolved external symbol "public: class std::shared_ptr<class JSBSim::FGAerodynamics> __cdecl JSBSim::FGFDMExec::GetAerodynamics(void)const "
(?GetAerodynamics@FGFDMExec@JSBSim@@QEBA?AV?$shared_ptr@VFGAerodynamics@JSBSim@@@std@@XZ) referenced in function "public: __cdecl JSBSimInterface::JSBSimInterface(double)"
(??0JSBSimInterface@@QEAA@N@Z)
JSBSimInterface.obj : error LNK2019: unresolved external symbol "public: class std::shared_ptr<class JSBSim::FGAircraft> __cdecl JSBSim::FGFDMExec::GetAircraft(void)const "
(?GetAircraft@FGFDMExec@JSBSim@@QEBA?AV?$shared_ptr@VFGAircraft@JSBSim@@@std@@XZ) referenced in function "public: bool __cdecl JSBSimInterface::Open(class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > const &)" (?Open@JSBSimInterface@@QEAA_NAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
JSBSimInterface.obj : error LNK2019: unresolved external symbol "public: class std::shared_ptr<class JSBSim::FGPropagate> __cdecl JSBSim::FGFDMExec::GetPropagate(void)const "
(?GetPropagate@FGFDMExec@JSBSim@@QEBA?AV?$shared_ptr@VFGPropagate@JSBSim@@@std@@XZ) referenced in function "public: __cdecl JSBSimInterface::JSBSimInterface(double)"
(??0JSBSimInterface@@QEAA@N@Z)
JSBSimInterface.obj : error LNK2019: unresolved external symbol "public: class std::shared_ptr<class JSBSim::FGAuxiliary> __cdecl JSBSim::FGFDMExec::GetAuxiliary(void)const "
(?GetAuxiliary@FGFDMExec@JSBSim@@QEBA?AV?$shared_ptr@VFGAuxiliary@JSBSim@@@std@@XZ) referenced in function "public: __cdecl JSBSimInterface::JSBSimInterface(double)"
(??0JSBSimInterface@@QEAA@N@Z)
JSBSim_SFunction.mexw64 : fatal error LNK1120: 8 unresolved externals The environment should be the same as you: JSBSim release 1.1.8 installer, MATLAB R2020b Update 6, Visual C++ 2019 compiler. I copied and replaced everything in the Thanks a lot for the assistance. |
@huweius it looks like the mex compiler doesn't see the class You should double check the arguments of your mex command. In my system I have this command within the script file
where
|
Hello, Below is the copy of matlab command screen, with the error: Building with 'MinGW64 Compiler (C++)'. |
@Dim1303 I see that you are using Matlab v2018a. My tests are valid for Matlab v2020a and v2020b. In addition, you are using MinGW64 Compiler (C++); my suggestion is to use Visual Studio 2019 Community Edition. |
Professor De Marco, thank you so much for the support. I have uninstalled and installed the JSBSim to do the modifications step by step (just to check), now I'm using the Matlab v2020a with the MEX configured to use 'Microsoft Visual C++ 2019 (C)' for C language compilation. The error is a little bit different now: -- Error in myJSBSimSimulinkCompile (line 5) |
@Dim1303 you are right, the file
At this point your compilation should work fine. |
Thank you so much @agodemar. It worked perfectly. |
That's weird, the following line is supposed to include all files named Line 34 in c685645
OK we could provide them under a new installer category |
I'm afraid I'm still getting a different error for building this S-function despite copying all of the required headers and following Prof. de Marco's instructions. Compiler used was MEX with VS 2019. How could this type of type-casting error exist?
|
@huweius you most likely downloaded the header files from the |
Thanks! That does solve it. |
Well, I just realized this line has been modified after |
This should now be fixed in JSBSim version |
Oh man ! I forgot to include |
This has been fixed by the commit 131517f. I also took this opportunity to add the license files to the Windows installer by the way. |
@bcoconni thanks |
This is now fixed in release Thanks. |
@Dim1303 See #548. You can follow the instructions to build matlab mex file with MinGW-w64 toolset. |
FYI, the Matlab guys just announced that Matlab actions for GitHub are now available for Windows and MacOS X. I'll therefore update our CI later this week to check that JSBSim S-Function also builds successfully on Windows and MacOS X (currently only checking on Linux). |
Should be useful in terms of minimizing the number of Matlab build issue requests we get 😉 |
Well |
False alarm, the header file |
MATLAB S-Functions are now built by our CI workflow for the 3 major platforms (Windows, Linux, MacOSX) since the commit db4d967 that I pushed yesterday night. CMake is now taking care of building the S-Function from the ground up as soon as you set the flag For the users who use the Windows installer to install JSBSim, I guess we should also update |
I'll take a look in terms of Visual Studio, although I won't be able to fully test since I don't have a copy of Matlab. Do you know off-hand if the matlab github action setup can be installed locally so that I could at least test building locally. I still wouldn't be able to actually test the s-function DLL in Matlab/Simulink. @agodemar I'm pretty sure has a Matlab license, so he's probably the best bet in terms of being able to fully test this on Windows with Visual Studio etc. I am a bit confused about the combination of the CMake build support we now have and I guess similar to how we have support for building JSBSim using CMake, the official mechanism, but also provide Visual Studio .sln/.vcxproj files? |
To set Documentation on this can be found at - https://docs.microsoft.com/en-us/cpp/build/customize-cmake-settings?view=msvc-170 |
I agree they are doing the same thing but, in my opinion, there are not targeting the same audience.
|
My wild guess, could be way off 😉 is that 90+% of Matlab users simply want a pre-built binary of the S-Function when downloading the Windows installer so that they can incorporate it into their larger Simulink setup with no need or desire to compile the S-function code.
My guess is they don't really want to compile either the JSBSim lib or the S-Function. So I guess I was wondering whether it makes sense in terms of catering to the ~10% (wild guess) of Matlab users who want to make source code changes and then compile to offer both the CMake option as well as the |
I would tend to be in complement agreement with you but @agodemar told me otherwise in discussion #484.
However if we reconsider this statement, it's quite easy to release the MEX files that our GitHub actions build. |
Ah, I assumed once you had added the CMake support for building the But glancing through that discussion I noticed your comment:
Which I guess means that if we were to try and supply pre-built
Which does seem like a whole lot of work 😉 So if we don't supply pre-built And as you say if a user wants to make say source changes to JSBSim as well before building their So pretty much ignore everything else I said earlier 😉 So let's leave both compile options, and maybe generate a Wiki page with build info/instuctions, e.g. how to configure CMake in Visual Studio for building the |
Agreed |
Well, the installer is not managed by CMake but by our CI workflow: jsbsim/.github/workflows/cpp-python-build.yml Lines 385 to 419 in d3536e9
and the list of files that should be installed by the installer is managed in the file
As long as the dull work is done by computers this is not much of an issue 😄. In my opinion, the real problem would be that we cannot cover every possible combinations of MATLAB versions and compiler versions: at the moment, GitHub supports
Yes, I think all the needed material is in the comments of the current issue. All we need is to collect it and make a tutorial out of it. I guess we need to release |
I'd like to clarify the parameters that are used by the
jsbsim/matlab/JSBSimSimulinkCompile.m Line 5 in 29904e5
|
Well, so I RTFM for
According to the
According to the |
…e folder installed by the Windows installer. See discussion in issue JSBSim-Team#491.
This is now implemented by commit 2c12a7b. |
…e folder installed by the Windows installer. See discussion in issue JSBSim-Team#491.
Following the release of JSBSim |
|
FYI I have copied the content of this issue in a README file located in Of course, comments are welcome about the content of |
Dear Professor De Marco, I have installed JSBSim (version 1.1.13) last week, but I have a problem with outputs from S-function in Simulink. I cannot figure out why model doesn't accept the throttle command from the joystick. I have checked functionality of the joystick, and it's working, but when I want to drive the plane (c172p) in the simulation environment, there is a problem with generating thrust. Furthermore, I have noticed that elevation and aileron commands work only when I set the initial velocity (w, vc, or vt) in the initialization xml file. Do you have any suggestions how to fix this problem, and how can I set up the files before running the Simulink model? Thanks in advance! Kind regards, |
@jevta23 you should open a new issue and give all possible details about your problem. |
Dear Professor @agodemar , Thanks for your quick reply! I have opened a new issue and tried to explain my problem. Kind regards, |
Hello JSBSimmers!
I have managed to download and install on Windows the JSBSim release v1.1.8 that includes the newly released interface to Matlab.
Yet, the interface doesn't work right out of the box on Windows unless you add some headers and do some extra work on Matlab side.
Here's what you can do to make it work:
The exact location
<JSBSim root>/
on your system depends on where you choose to install JSBSim.*.hxx
files related tosimgear
. You have to copy all those missing header files, including their directory structure, from the source tree to the following local installation tree:@bcoconni This is an important step that should be fixed in next releases when packaging the JSBSim setup executable on Windows.
The following steps are tested for Matlab v2020b, which I have installed on my system.
To compile the file
<JSBSim root>/matlab/JSBSim_SFunction.cpp
and get the MEX-FileJSBSim_SFunction.mexw64
on Windows, you need a working C++ compiler. Among the available options, I suggest you to go for Visual Studio 2019 Community Edition.Once you have a working C++ development environment, from Matlab command line you need to tell the MEX utility what is the default C++ compiler. You do this with the following command:
[Matlab prompt]>> mex -setup CPP
MEX will detect your C++ compiler and will be configured to build your
*.mexw64
files.<JSBSim root>/matlab/JSBSimSimulinkCompile.m
to build your own MEX-file.First of all, copy the script
<JSBSim root>/matlab/JSBSimSimulinkCompile.m
to your own version<JSBSim root>/myJSBSimSimulinkCompile.m
in the root of your JSBSim installation directory. This makes sense, because we want a Matlab EXecutable (MEX) that lives besides<JSBSim root>/JSBSim.exe
, and must reach all input files in the directoriesaircraft
,engine
,scripts
, andsystems
.This is how the script
<JSBSim root>/myJSBSimSimulinkCompile.m
should look like:If you point the current Matlab Working Directory to
<JSBSim root>/
and run the above M-file from the Matlab editor or from the command line:[Matlab prompt]>> myJSBSimSimulinkCompile
you'll get the MEX-file
<JSBSim root>/JSBSim_SFunction.mexw64
.<JSBSim root>/JSBSim_SFunction.mexw64
.Download from the sources the following files:
TestJSBSim.m
andex737cruise.slx
and save them in<JSBSim root>/
, besides<JSBSim root>/JSBSim_SFunction.mexw64
.@bcoconni These two files are missing from those packaged in the JSBSim setup executable on Windows. Probably this is fine, but we'll have to adjust our readme files to tell users how to start working with them on Matlab.
This is how
<JSBSim root>/TestJSBSim.m
will look like:and this is a screenshot of Simulink when you open the file
<JSBSim root>/ex737cruise.slx
:In particular, this is how the Simulink block named
JSBSim_SFunction
appears when you double-click on it:When you run the test script you'll have this output in Matlab command window:
and in Simulink you'll have the following outputs:
So you just have to try it out and adapt this workflow to your needs.
The text was updated successfully, but these errors were encountered: