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

MEX build issue on Windows #735

Merged
merged 1 commit into from
Sep 26, 2022
Merged

Conversation

bcoconni
Copy link
Member

As reported by @fkg-ctsi (see below), the build of the MATLAB S-function is broken since we allowed JSBSim to be built as a DLL. In order to avoid the build failing when JSBSim is compiled as a static library, the flag JSBSIM_STATIC_LINK is now passed to the mex compiler.

Discussed in #734

Originally posted by fkg-ctsi September 23, 2022
Hi there!
Firstly, thank you so much for all of the continued development and support over the years. This project has really helped make this industry more accessible!

I have a (likely) noob question re: compiling the S-Function using MEX.

I've been following the guide, and when I get to the step to compile with mex, I get a large link error dump.

Here is a snippet:

Error using mex
   Creating library JSBSim_SFunction.lib and object JSBSim_SFunction.exp
LINK : warning LNK4217: symbol '??0SGPath@@QEAA@P6A?AUPermissions@0@AEBV0@@Z@Z (public: __cdecl
SGPath::SGPath(struct SGPath::Permissions (__cdecl*)(class SGPath const &)))' defined in
'JSBSim.lib(sg_path.obj)' is imported by 'JSBSim_SFunction.obj' in function '"void __cdecl
mdlInitializeConditions(struct SimStruct_tag *)" (?mdlInitializeConditions@@YAXPEAUSimStruct_tag@@@Z)'
...
...
JSBSim_SFunction.mexw64 : fatal error LNK1120: 13 unresolved externals

For reference, I am using VS Community 2019, and Matlab/Simulink 2022b (Really hoping that this isn't the issue)

Admittedly, I am a MEX noob and only functional in C++, but would really appreciate a nudge in where to start investigating a path forwards.

Thanks!

@bcoconni bcoconni requested a review from agodemar September 24, 2022 12:53
@bcoconni bcoconni added the MATLAB Topics linked to the MATLAB S-Function label Sep 24, 2022
@codecov
Copy link

codecov bot commented Sep 24, 2022

Codecov Report

Merging #735 (f1411bf) into master (a5a4369) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #735   +/-   ##
=======================================
  Coverage   22.51%   22.51%           
=======================================
  Files         167      167           
  Lines       19146    19146           
=======================================
  Hits         4311     4311           
  Misses      14835    14835           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@bcoconni
Copy link
Member Author

@agodemar would you mind checking if the S-Function compiles again with the Windows command line from matlab/JSBSimSimulinkCompile.m ? Thanks.

@agodemar agodemar merged commit 8b0a22a into JSBSim-Team:master Sep 26, 2022
@agodemar
Copy link
Contributor

@bcoconni I have merged your recent fix and let you know if the Matlab v2022b compiles

@agodemar
Copy link
Contributor

@bcoconni
After merging your last modification I configured the compilation of JSBSim on Windows from the sources using CMake:
JSBAim_Matlab_01
JSBAim_Matlab_02

Then I successfully compiled both JSBSim.exe and JSBSim_SFunction.mexw64 on Windows:

JSBAim_Matlab_03
JSBAim_Matlab_04

Finally, I copied all the necessary files in JSBSim root directory and successfully tested the example Simulink model ex737cruise.slx, which includes the latest modifications in terms of I/O signal configurations via an XML file (see ex737cruise_io.xml)

JSBAim_Matlab_05
JSBAim_Matlab_06
JSBAim_Matlab_07
JSBAim_Matlab_08
JSBAim_Matlab_09
JSBAim_Matlab_10

Please guide me in the finale step: take the release version incorporating this latest feature and compile the M-file JSBSimSimulinkCompile.m. It looks like VS 2022 Community Edition compiles it fine. Need to check if the same happens using Matlab's MEX compiler.

@bcoconni
Copy link
Member Author

Thanks @agodemar for testing the procedure to build the S-Function with CMake.

Please guide me in the finale step: take the release version incorporating this latest feature and compile the M-file JSBSimSimulinkCompile.m. It looks like VS 2022 Community Edition compiles it fine. Need to check if the same happens using Matlab's MEX compiler.

For this part, I guess you'll need to follow the steps described in our MATLAB README (which was written from your input in the issue #491 😊). Of course, you can skip the part about downloading and installing JSBSim from the Windows installer JSBSim-1.1.12-setup.exe as you already built the DLL.

@agodemar
Copy link
Contributor

@bcoconni you mean that these modification is already bundled in the current setup package downloadable from the release section?

Don't we have to wait that the CI workflow makes a new package?

@bcoconni
Copy link
Member Author

@bcoconni you mean that these modification is already bundled in the current setup package downloadable from the release section?

@agodemar No, I meant to ask if you could build the S-Function from scratch as per the instructions from our MATLAB README. This is a different means to build the S-Function than using CMake. The point is to check that the default parameters of the file matlab/JSBSimSimulinkCompile.m are correctly set in order to build the S-Function without the user needing to tweak the file content.

@bcoconni bcoconni deleted the MATLAB-static-link branch October 15, 2022 14:09
bcoconni added a commit to bcoconni/jsbsim that referenced this pull request Nov 5, 2022
…ction compile commands. (JSBSim-Team#735)

I will be checking this new features on my Windows box, with Matlab v2022b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MATLAB Topics linked to the MATLAB S-Function
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants