# Compiling libraries in Linux

**URL:** <https://forums.unrealengine.com/t/compiling-libraries-in-linux/400275>\
**Category:** Platform & Builds\
**Tags:** third-party-librarie, unreal-engine, question\
**Created:** [July 17, 2017, 9:46pm UTC](https://forums.unrealengine.com/t/compiling-libraries-in-linux/400275 "2017-07-17T21:46:48Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_24cff47d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_24cff47d](https://forums.unrealengine.com/u/anonymous_user_24cff47d)\
**Post date:** [July 17, 2017, 9:46pm UTC](https://forums.unrealengine.com/t/compiling-libraries-in-linux/400275/1 "2017-07-17T21:46:48Z")

</div>

We have a plugin which uses 3rd party library. I gather that we need to compile this 3rd party library using Clang and libc++. To understand how to use Unreal’s built-in version of libc++, I was looking in to BuildThirdPaty.sh to see how Unreal does that. However I can’t find anywhere in this script statements that sets up clang and libc++. It seems that this script just invokes individual make for some 3rd party libraries.

So my question is, how do I invokes Unreal build system to compile my plugin’s third party libraries and make sure same Clang and libc++ versions are used as rest of the Unreal? It would be also useful if someone can tell us which version of libc++ is used by specific Unreal versions and what compiler flags should we pass on.

---

<div class="post-metadata">

**Author:** ![RCL](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RCL](https://forums.unrealengine.com/u/RCL)\
**Post date:** [July 17, 2017, 9:56pm UTC](https://forums.unrealengine.com/t/compiling-libraries-in-linux/400275/2 "2017-07-17T21:56:46Z")

</div>

You can use these switches when building your library (for simplicity assuming that UE4\_THIRD\_PARTY\_DIR holds the absolute path to Engine/Source/ThirdParty directory):

Compile:

```
-nostdinc++ -I $UE_THIRD_PARTY_DIR/Linux/LibCxx/include/ -I $UE_THIRD_PARTY_DIR/Linux/LibCxx/include/c++/v1

```

Link:

```
-nodefaultlibs -L $UE_THIRD_PARTY_DIR/Linux/LibCxx/lib/Linux/x86_64-unknown-linux-gnu/ $UE_THIRD_PARTY_DIR/Linux/LibCxx/lib/Linux/x86_64-unknown-linux-gnu/libc++.a $UE_THIRD_PARTY_DIR/Linux/LibCxx/lib/Linux/x86_64-unknown-linux-gnu/libc++abi.a -lm -lc -lgcc_s -lgcc

```

In general, if you are not passing STL types between your code and any Unreal module, you may be fine using libstdc++, although you’d need to double check that you won’t run into either binary compatibility (if you don’t redistribute it) or licensing (if you do redistribute it) problems. This depends on your target audience and target Linux distributions.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_24cff47d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_24cff47d](https://forums.unrealengine.com/u/anonymous_user_24cff47d)\
**Post date:** [July 20, 2017, 5:10am UTC](https://forums.unrealengine.com/t/compiling-libraries-in-linux/400275/3 "2017-07-20T05:10:07Z")

</div>

I tried this out and surprising its not working (I’m surprised because this is exactly the options LinuxToolChain.cs in UnrealBuildTool specifies). While my libraries gets compiled successfully, the linking to executable end up with tons of error messages such as `undefined reference to `std::\_\_1::…`. One things I suspect is that clang is ignoring -nostdinc++ for executables and falls back to GCC headers because I believe std::\_\_1 indicates linking must be done to libstdc++ and not libc++.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_24cff47d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_24cff47d](https://forums.unrealengine.com/u/anonymous_user_24cff47d)\
**Post date:** [July 20, 2017, 5:20am UTC](https://forums.unrealengine.com/t/compiling-libraries-in-linux/400275/4 "2017-07-20T05:20:27Z")

</div>

Update: if I replace -nodefaultlibs with -stdlib=libc++ then I don’t get these compile errors.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_24cff47d](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_24cff47d](https://forums.unrealengine.com/u/anonymous_user_24cff47d)\
**Post date:** [July 20, 2017, 10:30am UTC](https://forums.unrealengine.com/t/compiling-libraries-in-linux/400275/5 "2017-07-20T10:30:43Z")

</div>

Another quick question: do I need -std:c++14 as well? I am using Unreal 4.15.3.

---

<div class="post-metadata">

**Author:** ![RCL](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RCL](https://forums.unrealengine.com/u/RCL)\
**Post date:** [July 20, 2017, 2:23pm UTC](https://forums.unrealengine.com/t/compiling-libraries-in-linux/400275/6 "2017-07-20T14:23:31Z")

</div>

clang does not ignore that option when used from UBT, so there may be more factors at play. You can always get the full invocation of clang from both UBT and your library’s build system and compare if you want to drill deeper.

We switched to -std=c++14 in 4.15, so you may also use it. But, it is not as important unless you are passing C++ classes between different dynamic libraries (I recommend against this practice - for the sake of binary compatibility your library’s API should be extern “C” {…}).

---

<div class="post-metadata">

**Author:** ![Alex.Duran](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Alex.Duran](https://forums.unrealengine.com/u/Alex.Duran)\
**Post date:** [March 29, 2018, 6:30pm UTC](https://forums.unrealengine.com/t/compiling-libraries-in-linux/400275/7 "2018-03-29T18:30:52Z")

</div>

I’m adding this comment so that if someone else searches for this thread they can save a bit of effort.  
I was able to successfully link google breakpad **libraries** with this, at least the client libs, although I could never link the **executables**. I spent a lot of time looking at failed make results before realizing that it had already compiled the libs I needed (I used the -stdlib=libc++ suggested below).

---

<div class="post-metadata">

**Author:** ![PhilBax](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@PhilBax](https://forums.unrealengine.com/u/PhilBax)\
**Post date:** [September 7, 2018, 6:27pm UTC](https://forums.unrealengine.com/t/compiling-libraries-in-linux/400275/8 "2018-09-07T18:27:44Z")

</div>

I’m going through this right now, and wanted to comment and mention that -nodefaultlibs and -nostdinc++ are actually gcc flags, not clang flags. That said, I have successfully used gcc along with these flags to build my third party library with the UE4-included libc++ and integrate it with Unreal, so clang is not necessarily a requirement.

---

<div class="post-metadata">

**Author:** ![6r0m](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/6r0m/32/1194563_2.png) [@6r0m](https://forums.unrealengine.com/u/6r0m)\
**Post date:** [December 12, 2023, 7:10am UTC](https://forums.unrealengine.com/t/compiling-libraries-in-linux/400275/9 "2023-12-12T07:10:50Z")

</div>

yeap, this topic helps a lot with final building grpc framework (1.59) on Linux (Ubuntu 22.04) and integrating in UE (5.2).

**with `-nodefaultlibs` there is a problem with building.**

final command line:

```auto
CXXFLAGS="-fPIC -std=c++17 -nostdinc++ -I/home/igor/Documents/Repos/UnrealEngine/UnrealEngine/Engine/Source/ThirdParty/Unix/LibCxx/include -I/home/igor/Documents/Repos/UnrealEngine/UnrealEngine/Engine/Source/ThirdParty/Unix/LibCxx/include/c++/v1 -stdlib=libc++ -L/home/igor/Documents/Repos/UnrealEngine/UnrealEngine/Engine/Source/ThirdParty/Unix/LibCxx/lib/Unix/x86_64-unknown-linux-gnu/ -L/home/igor/Documents/Repos/UnrealEngine/UnrealEngine/Engine/Source/ThirdParty/Unix/LibCxx/lib/Unix/x86_64-unknown-linux-gnu/libc++.a -L/home/igor/Documents/Repos/UnrealEngine/UnrealEngine/Engine/Source/ThirdParty/Unix/LibCxx/lib/Unix/x86_64-unknown-linux-gnu/libc++abi.a -lm -lc -lgcc_s -lgcc
" cmake ../../Repos/grpc -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/home/igor/Documents/Build/grpc/install -DCMAKE_C_COMPILER=/home/igor/Documents/Repos/UnrealEngine/UnrealEngine/Engine/Extras/ThirdPartyNotUE/SDKs/HostLinux/Linux_x64/v21_clang-15.0.1-centos7/x86_64-unknown-linux-gnu/bin/clang -DCMAKE_CXX_COMPILER=/home/igor/Documents/Repos/UnrealEngine/UnrealEngine/Engine/Extras/ThirdPartyNotUE/SDKs/HostLinux/Linux_x64/v21_clang-15.0.1-centos7/x86_64-unknown-linux-gnu/bin/clang++ -DgRPC_SSL_PROVIDER=package -DOPENSSL_ROOT_DIR=/home/igor/Documents/Repos/openssl_1_1_1n

```

be ready to edit some grpc headers macro, wrap protobuf headers to undef UE macros, recompile abseil with different function calls (absent in UE environment), download make ssl with the same version as in UE and rebuild grpc with this.

also [this article](https://pgaleone.eu/2022/05/27/unreal-engine-third-party-linux-abi-compatibility/) clarifies UE Linux building process .

---

<div class="post-metadata">

**Author:** ![cyb201](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/cyb201/32/956468_2.png) [@cyb201](https://forums.unrealengine.com/u/cyb201)\
**Post date:** [December 13, 2023, 3:17am UTC](https://forums.unrealengine.com/t/compiling-libraries-in-linux/400275/11 "2023-12-13T03:17:14Z")

</div>

Hello! Thank you for your suggestion. I packaged Linux with the GRPC library in UE 5.1.1, but I found that the SSL library in UE5 seems to conflict with the SSL library in GRPC. May I ask if the GRPC library compiled using your method will have this issue? Thank you again!

---

<div class="post-metadata">

**Author:** ![6r0m](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/6r0m/32/1194563_2.png) [@6r0m](https://forums.unrealengine.com/u/6r0m)\
**Post date:** [December 13, 2023, 9:54am UTC](https://forums.unrealengine.com/t/compiling-libraries-in-linux/400275/12 "2023-12-13T09:54:26Z")

</div>

> [@6r0m](#):
>
> ` -DgRPC_SSL_PROVIDER=package -DOPENSSL_ROOT_DIR=/home/igor/Documents/Repos/openssl_1_1_1n`

as mentioned in the command above you need to place this lines when cmaking grpc to compile with custom ssl version. before that, check ssl version in the Engine Third Party, clone this ssl version from public openssl repo and make it.  
then modify `-DOPENSSL_ROOT_DIR=` to your local maked version from openssl.

when you cmake grpc (before `--build .`) - make sure that in log cmake found right ssl version from your maked `-DOPENSSL_ROOT_DIR=`

if all is ok, in your build.cs with cmaked grpc libs add:  
`AddEngineThirdPartyPrivateStaticDependencies(Target, "OpenSSL");`  
don’t add any additional ssl lib with this line.

---

<div class="post-metadata">

**Author:** ![whlkw](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@whlkw](https://forums.unrealengine.com/u/whlkw)\
**Post date:** [August 27, 2024, 2:56pm UTC](https://forums.unrealengine.com/t/compiling-libraries-in-linux/400275/14 "2024-08-27T14:56:57Z")

</div>

This should be input in command line?

```auto
CXXFLAGS="-fPIC -std=c++17 -nostdinc++ -I/home/igor/Documents/Repos/UnrealEngine/UnrealEngine/Engine/Source/ThirdParty/Unix/LibCxx/include -I/home/igor/Documents/Repos/UnrealEngine/UnrealEngine/Engine/Source/ThirdParty/Unix/LibCxx/include/c++/v1 -stdlib=libc++ -L/home/igor/Documents/Repos/UnrealEngine/UnrealEngine/Engine/Source/ThirdParty/Unix/LibCxx/lib/Unix/x86_64-unknown-linux-gnu/ -L/home/igor/Documents/Repos/UnrealEngine/UnrealEngine/Engine/Source/ThirdParty/Unix/LibCxx/lib/Unix/x86_64-unknown-linux-gnu/libc++.a -L/home/igor/Documents/Repos/UnrealEngine/UnrealEngine/Engine/Source/ThirdParty/Unix/LibCxx/lib/Unix/x86_64-unknown-linux-gnu/libc++abi.a -lm -lc -lgcc_s -lgcc
"

```

And run cmake, and make, I got compiling error…
