x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Using 3rd party libraries in cross-platform way

It looks like using 3rd party libraries involves building Windows DLLs and lib files and linking to them. However I need to generate Windows as well Linux builds of the game (my library is also portable cross-platform). What is the best way to use 3rd party libraries in cross-platform way in Unreal? Previously I thought I can just drop-in the code for the library in a folder, add include file and just compile. However doing this gave me an error related to pre-compiled header:

 Info ERROR: The first include statement in source file 'xxx.cpp' is trying to include the file 'stdio.h' as the precompiled header, but that file could not be located in any of the module's include search paths.

The usual suggestions such as changing order of the header didn't worked. Any suggestions would be helpful.

Product Version: Not Selected
Tags:
more ▼

asked Oct 29 '16 at 10:34 AM in C++ Programming

avatar image

sytelus
241 16 31 46

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

It seems the easiest way is to use compiled libraries with Unreal as opposed to dropping in the source code of the library in the Unreal project. I followed instructions at below page (with few changes) to use compiled version:

https://wiki.unrealengine.com/Linking_Static_Libraries_Using_The_Build_System

Changes required in above instructions:

  1. Use Multithreaded Dynamic Library as opposed to Static Library setting. If you don't do this then you will get error such as error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj and error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MD_DynamicDebug' in program.obj

  2. Make sure you don't have _CONSOLE or _DEBUG macros defined in Release build (see C/C++ > Preprocessors tab).

  3. Build both Release and Debug versions of library and put them in Libraries folder. Below is the code in my MyUEProject.Build.cs

Code:

 using UnrealBuildTool;
 using System.IO;
 public class FlyingTest : ModuleRules
 {
     private string ModulePath
     {
         get { return ModuleDirectory; }
     }
          
     private string ThirdPartyPath
     {
         get { return Path.GetFullPath( Path.Combine( ModulePath, "ThirdParty/" ) ); }
     }
     
     public FlyingTest(TargetInfo Target)
     {
         UEBuildConfiguration.bForceEnableExceptions = true;
         PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "RenderCore" });
         
         LoadThirdPartyLibrary(Target, "MavLinkCom");
     }
     
     public bool LoadThirdPartyLibrary(TargetInfo Target, string LibName)
     {
         bool isLibrarySupported = false;
 
         string LibrariesPath = Path.Combine(ThirdPartyPath, LibName, "Libraries");
         string PlatformString = (Target.Platform == UnrealTargetPlatform.Win64) ? "x64" : "x86";
         string ConfigurationString = (Target.Configuration == UnrealTargetConfiguration.Debug) ? "Debug" : "Release";
 
 
         if (Target.Platform == UnrealTargetPlatform.Win64)
         {
             isLibrarySupported = true;
  
             PublicAdditionalLibraries.Add(Path.Combine(LibrariesPath, PlatformString, ConfigurationString, LibName + ".lib")); 
         }
  
         if (isLibrarySupported)
         {
             // Include path
             PublicIncludePaths.Add( Path.Combine( ThirdPartyPath, LibName, "Includes" ) );
         }
  
         Definitions.Add(string.Format( "WITH_" + LibName.ToUpper() + "_BINDING={0}", isLibrarySupported ? 1 : 0 ) );
  
         return isLibrarySupported;
     }    
 }

more ▼

answered Oct 30 '16 at 09:55 AM

avatar image

sytelus
241 16 31 46

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Just to follow up... if you have C++ header-only library that you want to drop in to your game project then easiest way is to create folder Source > ThirdPary > MyHeaderOnlyLib > includes and then drop all your files in there. You can then include these files in UE4 C++ code as usual:

 #include "ThirdParty/MyHeaderOnlyLib/include/MyLib.hpp"
more ▼

answered Nov 22 '16 at 04:02 AM

avatar image

sytelus
241 16 31 46

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question