Matlab s-function linking - libraries in Visual Studio #405
Replies: 13 comments 24 replies
-
Yep, it looks like you've built the JSBSim_SFunction code as a release build and JSBSim has been built as a debug build. So either build the SFunction code as a debug build or build JSBSim as a release build and link against the release version of the .lib. |
Beta Was this translation helpful? Give feedback.
-
Right, that is what I'm struggling with. I tried to figure out how to build it as a release, and a "Release"-directory did show up in the JSBSim directory. But I can't locate a .lib there. I've tried to play around a bit in Visual Studio to find how to correctly build a release build, but no luck.
Thanks for your reply! |
Beta Was this translation helpful? Give feedback.
-
Okay, so one potentially confusing issue is that we have 2 ways of building JSBSim using Visual Studio. The first option is to make use of the provided Visual Studio solution/project file to build JSBSim. Which is what the majority of Visual Studio users are most familiar with. However using this option the project file doesn't generate a .lib file, it simply generates an .exe. The 2nd option is to build using CMake, which is the default for non-Windows platforms, and the 'official' way to build JSBSim. In the CMake case a .lib file is first created and this is then later on linked in to also generate a .exe file. The Visual Studio IDE from version 2017 onwards has included support in the IDE for building via CMake, see the following documentation which describes both Visual Studio options for building, i.e. via CMake and via the solution/project file. So in your case you'll need to make use of the CMake option. You'll see in the CMake build documentation references to debug and release. |
Beta Was this translation helpful? Give feedback.
-
This issue has been moved to "Discussions". The github issues are reserved for reporting bugs or new feature requests. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
The linker errors you listed above are because the JSBSim code includes calls to network/socket APIs but when you're building and linking your S-Function code via mex you're not including linker references to ws2_32.lib. |
Beta Was this translation helpful? Give feedback.
-
Two fast replies, thanks a lot! It solved that problem right away. I ended up using the library file that I got from installing instead of building, because then I was provided with a folder with library file and an include folder with header files. Now I have it working both on Windows and Linux. :D |
Beta Was this translation helpful? Give feedback.
-
Hi again, If someone with Matlab and Simulink (I run 2020b, but earlier versions could work) would be willing to help me out with this, I'll contact you. I've used it on both Linux and Windows, so either should work. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Just to confirm, my understanding is you've implemented some code to wrap JSBSim up as a Matlab S-Function? https://www.mathworks.com/help/simulink/sfg/example-of-a-basic-c-mex-s-function.html |
Beta Was this translation helpful? Give feedback.
-
In terms of organizing the code I would suggest just as we have python and julia wrappers in their own root level directories that we add a matlab directory. Now the s-function wrapper builds a shared lib/dll but requires access to matlab's header files, libs and tools like Lines 1 to 13 in 6e167e4 Ideally at a minimum I guess some documentation even just as a readme.md in the matlab directory explaining the functionality. |
Beta Was this translation helpful? Give feedback.
-
Looks like there is a matlab option for |
Beta Was this translation helpful? Give feedback.
-
There is also the possibility to integrate GitHub Actions, our automatic build workflow, with Matlab: https://it.mathworks.com/help/matlab/matlab_prog/continuous-integration-with-matlab-on-ci-platforms.html. Learn more here: https://github.com/matlab-actions/overview/blob/main/README.md |
Beta Was this translation helpful? Give feedback.
-
Yep, according to this link https://www.mathworks.com/solutions/continuous-integration.html
The CI tools do support the generation of MEX files. Although as you mentioned they're only available on Linux. So anyone using Matlab on Windows would need to build the s-function MEX file themselves. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi again!
For those who read my previous posts, my thesis is moving along nicely. I had to change my approach a bit and am now doing a Simulink interface using S-functions. It works nicely on my own Linux computer, and I am now trying to compile it on a Windows computer. (This is inspired by this JSBSim-Matlab repo, I will post my solution once I have cleaned it up a bit)
My problem now is on the Windows computer. Since I am using S-functions, I use the
mex
command in matlab. It looked like this for my Linuz computer:mex -v -R2017b CXXFLAGS='$CXXFLAGS -std=c++14' ./matlab/JSBSim_SFunction.cpp ./matlab/JSBSimInterface.cpp -I./src -L./src/.libs -lJSBSim
I am having trouble with the library files. I have tried to use Visual Studio 2019 and follow the JSBSim user guide, but it looks a bit different now than the screenshots in the user guide. I managed to build something, but I think it is a debug version because when I run my mex command I get these errors:
Google told me this has something to do with release vs debug configurations. Currently I'm locating them in the path
jsbsim\out\install\x64-Debug (default)\lib
since that is the only place I found lib-files, but I guess that is part of my problem since it's debug.Does anyone have some advice on how I link to (or create?) the correct library file on Windows?
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions