步骤:
1.从JSBSim官网下载源码
2.将JSBSim编译为静态库(lib,多线程DLL)
3.ue4项目根目录建立文件件ThirdParty->JSBSim->include、lib文件夹
4.将JSBSim源码中src文件件拷贝到include文件夹,将生成的lib静态库拷贝到lib文件夹
5.在ue4项目的build.cs文件中定义
using UnrealBuildTool; using System.IO; public class FlightSimulator : ModuleRules { private string ModulePath { // get { return Path.GetDirectoryName(RulesCompiler.GetModuleFilename(this.GetType().Name)); } get { return ModuleDirectory; } } private string ThirdPartyPath { get { return Path.GetFullPath(Path.Combine(ModulePath, "../../ThirdParty/")); } } private string MyLibPath //第三方库MyTestLib的目录 { get { return Path.GetFullPath(Path.Combine(ThirdPartyPath, "JSBSim")); } } public FlightSimulator(ReadOnlyTargetRules Target) : base(Target) { //PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; PrivatePCHHeaderFile = "Public/FlightSimulator.h"; PublicIncludePaths.AddRange(new string[] { "FlightSimulator/Public/Player", "FlightSimulator/Public/System", "FlightSimulator/Public/System/Radar", "FlightSimulator/Public/Weapon", "FlightSimulator/Public/Weapon/Missile", "FlightSimulator/Public/Effect", "FlightSimulator/Public/UI", "FlightSimulator/Public/AI", "FlightSimulator/Public/Sound", "FlightSimulator/Public/Online", "FlightSimulator/Public/Flight", "FlightSimulator/Public/Flight/Others", }); PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EasyFM"}); PrivateDependencyModuleNames.AddRange(new string[] { }); // Uncomment if you are using Slate UI // PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" }); // Uncomment if you are using online features // PrivateDependencyModuleNames.Add("OnlineSubsystem"); // To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true LoadThirdPartyLib(Target); } public bool LoadThirdPartyLib(ReadOnlyTargetRules Target) { bool isLibrarySupported = false; if ((Target.Platform == UnrealTargetPlatform.Win64) || (Target.Platform == UnrealTargetPlatform.Win32))//平台判断 { isLibrarySupported = true; System.Console.WriteLine("----- isLibrarySupported true"); string LibrariesPath = Path.Combine(MyLibPath, "lib"); PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, "JSBSim.lib"));//加载第三方静态库.lib } if (isLibrarySupported) //成功加载库的情况下,包含第三方库的头文件 { // Include path System.Console.WriteLine("----- PublicIncludePaths.Add true"); PublicIncludePaths.Add(Path.Combine(MyLibPath, "include")); } return isLibrarySupported; } }
6.在需要使用的地方#include "../ThirdParty/JSBSim/include/FGFDMExec.h"
7.JSBSim依旧会报错,不过不影响使用
8.JSBSim生成静态库一定要是多线程DLL(/MD),否则会报错