# Recompile UE4 PhysX libraries (Linux, Windows etc)

**URL:** <https://forums.unrealengine.com/t/recompile-ue4-physx-libraries-linux-windows-etc/1251523>\
**Category:** Platform & Builds\
**Tags:** physx, unreal-engine\
**Created:** [August 5, 2023, 11:28am UTC](https://forums.unrealengine.com/t/recompile-ue4-physx-libraries-linux-windows-etc/1251523 "2023-08-05T11:28:18Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![richardbaxter](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@richardbaxter](https://forums.unrealengine.com/u/richardbaxter)\
**Post date:** [August 14, 2023, 11:37am UTC](https://forums.unrealengine.com/t/recompile-ue4-physx-libraries-linux-windows-etc/1251523/3 "2023-08-14T11:37:35Z")

</div>

See Windows Part 2b/Linux Part 2b below for a more robust method to recompile the PhysX library for Windows/Linux respectively (UE4.14.3).

This is a better method using RunUAT.bat (from [PhysX Source Guide | Unreal Engine Community Wiki](https://unrealcommunity.wiki/physx-source-guide-0mvucbzi) / [[URGENT] Default Movement Component causing major dedicated server performance issues (Linux Only)](https://forums.unrealengine.com/t/urgent-default-movement-component-causing-major-dedicated-server-performance-issues-linux-only/404860))

**Windows**

_**Windows Part 1 (Download UE4.14.3 source):**_

```auto
Open git command line
cd X:/USERFOLDER
git clone https://github.com/EpicGames/UnrealEngine.git
cd UnrealEngine
git checkout tags/4.14.3-release
apply fix2 (`Failed to download 'http://cdn.unrealengine.com/dependencies/..': The remote server returned an error`);
	go to https://github.com/EpicGames/UnrealEngine/releases/tag/4.14.3-release
	download Commit.gitdeps.xml 
	copy Commit.gitdeps.xml X:/USERFOLDER/UnrealEngine/Engine/Build/Commit.gitdeps.xml
Install Linux cross-compile toolchain for UE4.14.3;
	https://docs.unrealengine.com/4.26/en-US/SharingAndReleasing/Linux/GettingStarted/	
	https://cdn.unrealengine.com/CrossToolchain_Linux/v8_clang-3.9.0-centos7.exe
Setup.bat [download dependencies]	
GenerateProjectFiles.bat

```

_**Windows Part 2a (patch UE4.14.3 PhysX library for Linux UB20.04):**_

```auto
Open;
	X:\USERFOLDER\UnrealEngine\Engine\Source\ThirdParty\PhysX\PxShared\src\compiler\cmake\Linux\CMakeLists.txt
	X:\USERFOLDER\UnrealEngine\Engine\Source\ThirdParty\PhysX\PhysX_3.4\Source\compiler\cmake\Linux\CMakeLists.txt
	X:\USERFOLDER\UnrealEngine\Engine\Source\ThirdParty\PhysX\APEX_1.4\compiler\cmake\Linux\CMakeLists.txt
remove all instances; " -ffast-math"

```

_**Windows Part 2b (recompile UE4.14.3 PhysX library for Windows):**_

```auto
apply fix6 (`Program.Main: ERROR: AutomationTool terminated with exception: System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified.. UnrealEngine\Engine\Source\Programs\AutomationTool\AutomationUtils\ProcessUtils.cs :line 797`);
	open X:/USERFOLDER/UnrealEngine/Engine/Source/Programs/AutomationTool/Scripts/BuildPhysX.Automation.cs
	//[RequireP4]	(comment out line)
cd X:/USERFOLDER/UnrealEngine/Engine/Build/BatchFiles
call RunUAT.bat BuildPhysX -TargetPlatforms=Win64 -TargetConfigs=profile+release+checked -TargetWindowsCompilers=VisualStudio2015 -SkipCreateChangelist

```

_**Windows Part 3 (compile UE4.14.3 with updated PhysX library):**_

```auto
Open X:/USERFOLDER/UnrealEngine/UE4.sln
select build type [Development/..]
build
cd Engine/Binaries/Win64/
open UE4Editor.exe

```

**Linux**

_**Linux Part 1 (Download UE4.14.3 source):**_

```auto
cd /USERFOLDER
git clone https://github.com/EpicGames/UnrealEngine.git
cd UnrealEngine
git checkout tags/4.14.3-release
apply fix1 (`Package clang-3.9 is not available, but is referred to by another package`);
	nedit /USERFOLDER/UnrealEngine/Engine/Build/BatchFiles/Linux/Setup.sh
	remove `clang-3.9` reference from `DEPS` `assume the latest, this is going to be a moving target`
apply fix4 (`Package clang-3.9 is not available, but is referred to by another package`);
	download and extract https://releases.llvm.org/3.9.0/clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz
	cd clang+llvm-3.9.0-x86_64-linux-gnu-ubuntu-16.04
	sudo cp -r * /usr/local/
	sudo ln -s /usr/local/bin/clang++ /usr/local/bin/clang++-3.9
apply fix2 (`Failed to download 'http://cdn.unrealengine.com/dependencies/..': The remote server returned an error`);
	go to https://github.com/EpicGames/UnrealEngine/releases/tag/4.14.3-release
	download Commit.gitdeps.xml 
	cp Commit.gitdeps.xml /USERFOLDER/UnrealEngine/Engine/Build/Commit.gitdeps.xml
./Setup.sh [download dependencies]	
./GenerateProjectFiles.sh

```

_**Linux Part 2b (recompile UE4.14.3 PhysX library for Linux) [using Windows]:**_

```auto
Switch to Windows UE4.14.3 source folder
Add an environment variable named LINUX_ROOT, the value of which is the absolute path to your toolchain (without a trailing backslash): 
	Control Panel->System->Advanced system settings->Advanced->Environment variables->New
		LINUX_ROOT
		C:\UnrealToolchains\v8_clang-3.9.0-centos7\x86_64-unknown-linux-gnu
apply fix6 (already done)
cd X:/USERFOLDER/UnrealEngine/Engine/Build/BatchFiles
call RunUAT.bat BuildPhysX -SkipCreateChangelist -SkipSubmit -TargetLibs=PhysX+APEX -TargetPlatforms=Linux -TargetConfigs=checked+profile+release
copy all X:\USERFOLDER\UnrealEngine\Engine\Source\ThirdParty\PhysX\Lib\Linux\x86_64-unknown-linux-gnu to Linux

```

_**Linux Part 3 (compile UE4.14.3 with updated PhysX library):**_

```auto
cd /USERFOLDER
apply fix1 (already done)
apply fix2 (already done);
apply fix3 (`The <sys/sysctl.h> header is deprecated and will be removed`);
	nedit /USERFOLDER/UnrealEngine/Engine/Source/Runtime/Core/Public/Linux/LinuxSystemIncludes.h &
	//#include <sys/sysctl.h>
apply fix4 (already done)
apply fix5 (`undefined symbol: __atan2f_finite`);
	rm /USERFOLDER/UnrealEngine/Engine/Source/ThirdParty/PhysX/Lib/Linux/x86_64-unknown-linux-gnu/*.a
	copy recompiled libraries X:\USERFOLDER\UnrealEngine\Engine\Source\ThirdParty\PhysX\Lib\Linux\x86_64-unknown-linux-gnu\*.a to /USERFOLDER/UnrealEngine/Engine/Source/ThirdParty/PhysX/Lib/Linux/x86_64-unknown-linux-gnu/
make ARGS="-clean"
make
cd Engine/Binaries/Linux/
./UE4Editor

```

For reference, the previous method I provided to recompile PhysX for Linux UE4.14.3 (using cmake-gui) throws an error at ~90% startup; `in nvidia::apex::ApexScene::destroy (this=<optimised out>) mModuleScenes.back()->release()`. If you wish to further debug the previous method;

- change all `clang 3.9.1` to `clang 3.9.0` (fix `appError called: Assertion failed: Assertion failed: ReaderPos + Num <= ReaderSize`)
- move `fix1` before `fix4`
- execute `make` for each sub library (`PhysX`, `APEX`)
- Repeat for each build type; `profile` or `checked` or `release` (see `set var in GUI list; CMAKE_BUILD_TYPE`)
- enable PhysX library debugging;
  - open `/USERFOLDER/UnrealEngine/Engine/Saved/UnrealBuildTool/BuildConfiguration.xml`
  - add inside `<BuildConfiguration>`: `<bDebugBuildsActuallyUseDebugCRT>true</bDebugBuildsActuallyUseDebugCRT>`

- build UE4Editor for debugging;  
`make ARGS="-clean"`  
`make UE4Editor-Linux-Debug`  
`cd Engine/Binaries/Linux/`  
`gdb -ex run --args UE4Editor-Linux-Debug`

---

_[View the full topic](https://forums.unrealengine.com/t/recompile-ue4-physx-libraries-linux-windows-etc/1251523)._
