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.
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:
Changes required in above instructions:
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
Make sure you don’t have _CONSOLE or _DEBUG macros defined in Release build (see C/C++ > Preprocessors tab).
Build both Release and Debug versions of library and put them in Libraries folder. Below is the code in my MyUEProject.Build.cs
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: