[UE4]Precompile Plugins - Build from Engine Source
Keywords: UE4, Engine Source Code, Without Source, Source Removed, Prebuilding, Precompile, Distributing
Related References
[UE4]Precompile Plugins - Build from Installed Engine
Solution
If want to distribute plugins with source removed, and allow project building from engine source (not installed distributions in launcher), do steps as shown in following content.
In this sample, we would package project in Shipping
Build.
We assumed that the plugin was named P1
, project which contains P1
with plugins private source was named TestTD
, project which contains P1
with private source removed was named TestTD2
.
1, Package plugin P1
(tutorial: [UE4]Precompile Plugins - Build from Installed Engine), then it would output two version libraries: Development
and Shipping
.
2, Copy all files of P1
which was contained in TestTD
:
Copy them to project TestTD2
, then remove all private source files:
Attention: Intermediate files of P1
must be copied from TestTD
, not be generated by TestTD2
.
Then generate Visual Studio project files in TestTD2
(We assumed that old files of Visual Studio project was cleaned):
3, Modify Build.cs
:
bUsePrecompiled = true;
Now you can build project TestTD2
from Visual Studio and start Editor.
If didn’t add bUsePrecompiled = true;
in Build.cs
, there’re some errors on building in Visual Studio:
1>LINK : error LNK2001: unresolved external symbol IMPLEMENT_MODULE_P1
1>P1Actor.gen.cpp.obj : error LNK2019: unresolved external symbol "public: __cdecl AP1Actor::AP1Actor(void)" (??0AP1Actor@@QEAA@XZ) referenced in function "void __cdecl InternalConstructor<class AP1Actor>(class FObjectInitializer const &)" (??$InternalConstructor@VAP1Actor@@@@YAXAEBVFObjectInitializer@@@Z)
1>P1Actor.gen.cpp.obj : error LNK2001: unresolved external symbol "protected: virtual void __cdecl AP1Actor::BeginPlay(void)" (?BeginPlay@AP1Actor@@MEAAXXZ)
1>P1Actor.gen.cpp.obj : error LNK2001: unresolved external symbol "public: virtual void __cdecl AP1Actor::Tick(float)" (?Tick@AP1Actor@@UEAAXM@Z)
1>D:\workspace\unreal_dev\TestTD2\Plugins\P1\Binaries\Win64\UE4Editor-P1-0003.dll : fatal error LNK1120: 4 unresolved externals
If there’re some building errors in your project, as shown above, you need to remove following files before try building again:
Then copy files:
TestTD\Plugins\P1\Intermediate\Build\Win64\UE4Editor\Development\P1
to directory TestTD2\Plugins\P1\Intermediate\Build\Win64\UE4Editor\Development\P1
.
4, New directory TestTD2
under TestTD2\Intermediate\Build\Win64
:
Then copy files which was outputed in packaging plugin P1
(in Step 1):
to the directory which was create previously: TestTD2\Intermediate\Build\Win64\TestTD2
If didn’t copy these files, there’re some errors at packaging project:
UATHelper: Packaging (Windows (64-bit)): ERROR: Missing precompiled manifest for 'P1'. This module was most likely not flagged for being included in a precompiled build - set 'PrecompileForTargets = PrecompileTargetsType.Any;' in P1.build.cs to override.
PackagingResults: Error: Missing precompiled manifest for 'P1'. This module was most likely not flagged for being included in a precompiled build - set 'PrecompileForTargets = PrecompileTargetsType.Any;' in P1.build.cs to override.
The reason is that files which was shown above are missed before packaging successfully:
6, Modify Target.cs
and Editor.Target.cs
. Add bPrecompile = true;
in them:
Otherwise there’re some errors at packaging:
UATHelper: Packaging (Windows (64-bit)): Building 2 actions with 32 processes...
UATHelper: Packaging (Windows (64-bit)): [1/2] TestTD2-Win64-Shipping.exe
UATHelper: inaries\Win64\TestTD2-Win64-Shipping.exe : fatal error LNK1120: 3 unresolved externals
UATHelper: Packaging (Windows (64-bit)): Module.P1.cpp.obj : error LNK2019: unresolved external symbol "private: static void __cdecl FDebug::CheckVerifyFailedImpl(char const *,char const *,int,wchar_t const *,...)" (?CheckVerifyFailedImpl@FDebug@@CAXPEBD0HPEB_WZZ) referenced in function "public: static void __cdecl FDebug::CheckVerifyFailed<wchar_t [1]>(
char const *,char const *,int,wchar_t const (&)[1])" (??$CheckVerifyFailed@$$BY00_W$$V@FDebug@@SAXPEBD0HAEAY00$$CB_W@Z)
UATHelper: Packaging (Windows (64-bit)): Module.P1.gen.cpp.obj : error LNK2001: unresolved external symbol "private: static void __cdecl FDebug::CheckVerifyFailedImpl(char const *,char const *,int,wchar_t const *,...)" (?CheckVerifyFailedImpl@FDebug@@CAXPEBD0HPEB_WZZ)
UATHelper: Packaging (Windows (64-bit)): Module.P1.gen.cpp.obj : error LNK2019: unresolved external symbol "public: __cdecl FLLMScope::FLLMScope(enum ELLMTag,enum ELLMTagSet,enum ELLMTracker)" (??0FLLMScope@@QEAA@W4ELLMTag@@W4ELLMTagSet@@W4ELLMTracker@@@Z) referenced in function "public: virtual class UClass * __cdecl TClassCompiledInDefer<class AP1Actor
>::Register(void)const " (?Register@?$TClassCompiledInDefer@VAP1Actor@@@@UEBAPEAVUClass@@XZ)
UATHelper: Packaging (Windows (64-bit)): Module.P1.gen.cpp.obj : error LNK2019: unresolved external symbol "public: __cdecl FLLMScope::~FLLMScope(void)" (??1FLLMScope@@QEAA@XZ) referenced in function "public: virtual class UClass * __cdecl TClassCompiledInDefer<class AP1Actor>::Register(void)const " (?Register@?$TClassCompiledInDefer@VAP1Actor@@@@UEBAPEA
VUClass@@XZ)
UATHelper: Packaging (Windows (64-bit)): D:\workspace\unreal_dev\TestTD2\Binaries\Win64\TestTD2-Win64-Shipping.exe : fatal error LNK1120: 3 unresolved externals
Now you could package project successfully.
Precompile in UE5
If there’s an error while building project without plugin source file with source building engine:
error LNK2001: unresolved external symbol _DllMainCRTStartup
You should change the BuildId
in UnrealEditor.modules (path: MyGame\Plugins\P1\Binaries\Win64\UnrealEditor.modules), e.g.:
{
"BuildId": "71b438f2-547b-4243-9c52-0277013dbaf4"
"Modules":
{
"SP_Interpolators": "UnrealEditor-SP_Interpolators.dll"
}
}
You can find your BuildId from other plugins.
For more details, see: MetaHuman Plugin
References
https://forums.unrealengine.com/t/metahuman-plugin-for-source-build/689576
Islands of memory begin to rise above the river of his life. At first they are little uncharted islands, rocks just peeping above the surface of the waters. Round about them and behind in the twilight of the dawn stretches the great untroubled sheet of water; then new islands, touched to gold by the sun.― Romain Rolland, Jean-Christophe - I