Getting linker errors when including JSBSim library #1220
-
Hello! I want to learn about JSBSim by using it as a library from a c++ program paired with raylib for visualizations. I've downloaded and installed JSBSim with the provided release executable I have a very basic main file: #include "raylib-cpp.hpp"
#include "FGFDMExec.h"
int main() {
constexpr int screenWidth = 800;
constexpr int screenHeight = 450;
raylib::Window window(screenWidth, screenHeight, "raylib-cpp - basic window");
SetTargetFPS(60);
auto FDMExec = new JSBSim::FGFDMExec();
while (!window.ShouldClose())
{
BeginDrawing();
window.ClearBackground(RAYWHITE);
DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
EndDrawing();
}
return 0;
} I first successfully compiled, linked, and executed the program with code only referencing the raylib library and its cpp wrapper. After that, I've included
These are the compiler flags VS2022 generates from my project configuration:
These are the linker flags:
I've tried compiling the .lib from source, but no luck. Also checked the paths, and spelling. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
How I've managed to get this project to link: I've added a BUILD_SHARED_LIBS=1 option in CMake and compiled the JSBSim project. This yielded me both .lib and .dll files, which I placed in my project root. So this is showing my lack of understanding of what the .lib file is in AppData. I was under the impression that it is a static library file, and it was the only thing I needed to make JSBSim to work in my project. I'm guessing the JSBSim installer placed this .dll file somewhere on my system, but VS2022 is not configured to use that path? Don't know if this is the correct way of doing things, so I'm not yet marking this question as answered. |
Beta Was this translation helpful? Give feedback.
-
So in terms of
So when building JSBSim you need to configure the build to either generate a static library or to generate a dynamic library (DLL) with an associated import lib. And when you build your application to make use of JSBSim you need to configure your build to specify whether you're wanting to make use of the JSBSim static library or the dynamic library (DLL).
From your initial error message you can tell based on the mention of |
Beta Was this translation helpful? Give feedback.
-
The most flexible for users, although more work for us, would be to release both a static lib and an import lib and DLL. That way users can choose to link to either the static lib or to the DLL via the import lib. Along the lines of how Visual Studio provides both options in terms of the C++ runtime library, although in their case there is an additional dimension of debug/release versions as well. |
Beta Was this translation helpful? Give feedback.
It seems that the provided JSBSim setup package contains the static lib version of jsbsim.lib.
To link against this static lib you have to define JSBSIM_STATIC_LINK, either in the visual studio project settings (C/C++->Preprocessor->Preprocessor Definitions) or by putting "#define JSBSIM_STATIC_LINK" in your code files before you include the JSBSim header files.
At least that's my understandig after I had a look at JSBSim_API.h. I think this info is missing in the JSBSim docu, or I haven't found it.
EDIT: Ok, I found it in the docu. The jsbsim.lib contained in the setup package is meant to be used to build the JSBSim Matlab S-Function and not to build general c++ applications.