# Can't link a Library

**URL:** <https://forums.unrealengine.com/t/cant-link-a-library/396690>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [June 27, 2017, 7:30pm UTC](https://forums.unrealengine.com/t/cant-link-a-library/396690 "2017-06-27T19:30:00Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![RicardoEPRodrigues](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ricardoeprodrigues/32/918672_2.png) [@RicardoEPRodrigues](https://forums.unrealengine.com/u/RicardoEPRodrigues)\
**Post date:** [June 27, 2017, 7:30pm UTC](https://forums.unrealengine.com/t/cant-link-a-library/396690/1 "2017-06-27T19:30:00Z")

</div>

I’m using Ubuntu 17.04 and the latest UE4 4.16.

I have a C++ library I want to include in my project, yet UE4 doesn’t seem to link the library correctly and gives me this error:

```
./UE4Editor: symbol lookup error: /home/ricardo/Documents/UnrealProjects/DivisactionIntg2/Binaries/Linux/libUE4Editor-DivisactionIntg2.so: undefined symbol: _ZN11Divisaction5DTime17setTimeCalculatorENSt3__110shared_ptrINS_15DTimeCalculatorEEE

```

* * *

From the beginning:

I edited the build.cs to include the library by adding these lines:

```
PublicLibraryPaths.Add (LibrariesPath);
PublicAdditionalLibraries.Add (Path.Combine (LibrariesPath, "libDivisaction.so"));
PublicIncludePaths.Add (Path.Combine (ThirdPartyPath, "Divisaction", "Includes"));

```

I compiled the project and it compiled fine, but when running it would fail and say the library was missing. After digging around I put the library in the Binaries folder and that solved the problem.

But even after compiling and finding the library, during UE4 is starting up it fails with the above error…

```
./UE4Editor: symbol lookup error: /home/ricardo/Documents/UnrealProjects/DivisactionIntg2/Binaries/Linux/libUE4Editor-DivisactionIntg2.so: undefined symbol: _ZN11Divisaction5DTime17setTimeCalculatorENSt3__110shared_ptrINS_15DTimeCalculatorEEE

```

**How can I fix this?**

---

<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:** [June 27, 2017, 8:18pm UTC](https://forums.unrealengine.com/t/cant-link-a-library/396690/2 "2017-06-27T20:18:17Z")

</div>

You might be affected by a bug with how UBT calculates RPATH for the libraries. In Engine/Sources/Programs/UnrealBuildTool/Linux/LinuxToolchain.cs, try replacing line 1117 (or so) with

```
string RelativePath = new FileReference(AdditionalLibrary).Directory.MakeRelativeTo(OutputFile.Reference.Directory);

```

(instead of current

```
string RelativePath = Utils.MakePathRelativeTo(...)

```

)

---

<div class="post-metadata">

**Author:** ![RicardoEPRodrigues](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ricardoeprodrigues/32/918672_2.png) [@RicardoEPRodrigues](https://forums.unrealengine.com/u/RicardoEPRodrigues)\
**Post date:** [June 28, 2017, 9:29am UTC](https://forums.unrealengine.com/t/cant-link-a-library/396690/3 "2017-06-28T09:29:42Z")

</div>

Thank you for the reply. Your solution removes the need to copy and paste the library in the binaries, but the last problem persists. It seems it can’t find the implementation of a function.

---

<div class="post-metadata">

**Author:** ![RicardoEPRodrigues](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ricardoeprodrigues/32/918672_2.png) [@RicardoEPRodrigues](https://forums.unrealengine.com/u/RicardoEPRodrigues)\
**Post date:** [June 28, 2017, 11:21am UTC](https://forums.unrealengine.com/t/cant-link-a-library/396690/4 "2017-06-28T11:21:50Z")

</div>

I tried other classes of the library and they all crash… It doesn’t seem the engine accepts the library…

---

<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:** [June 28, 2017, 2:21pm UTC](https://forums.unrealengine.com/t/cant-link-a-library/396690/5 "2017-06-28T14:21:32Z")

</div>

If the libDivisaction.so library is found (you can double check with running

```
ldd libUE4Editor-DivisactionIntg2.so

```

it should not have “not found” but instead point to libDivisaction.so), make sure that it contains the text for Divisaction::DTime::setTimeCalculator() function. You can run

```
 nm --demangle libDivisaction.so 

```

and grep for that function name. It should say “t” and not “U” next to it.

---

<div class="post-metadata">

**Author:** ![RicardoEPRodrigues](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ricardoeprodrigues/32/918672_2.png) [@RicardoEPRodrigues](https://forums.unrealengine.com/u/RicardoEPRodrigues)\
**Post date:** [June 28, 2017, 2:34pm UTC](https://forums.unrealengine.com/t/cant-link-a-library/396690/6 "2017-06-28T14:34:42Z")

</div>

It doesn’t seem to have the library on the output of ldd…

```
$ ldd libUE4Editor-DivisactionIntg2.so
linux-vdso.so.1 => (0x00007ffd77466000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f032bbc1000)
libUE4Editor-Engine.so => not found
libUE4Editor-AIModule.so => not found
libUE4Editor-Core.so => not found
libUE4Editor-CoreUObject.so => not found
libUE4Editor-UMG.so => not found
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f032b8b6000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f032b4ef000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f032b2d8000)
/lib64/ld-linux-x86-64.so.2 (0x0000558781bf5000)
```

---

<div class="post-metadata">

**Author:** ![RicardoEPRodrigues](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ricardoeprodrigues/32/918672_2.png) [@RicardoEPRodrigues](https://forums.unrealengine.com/u/RicardoEPRodrigues)\
**Post date:** [June 28, 2017, 4:15pm UTC](https://forums.unrealengine.com/t/cant-link-a-library/396690/7 "2017-06-28T16:15:33Z")

</div>

Update: it does find the library:

```
libDivisaction.so => /home/ricardo/Documents/UnrealProjects/DivisactionIntg2/Binaries/Linux/./libDivisaction.so (0x00007fb1a4f54000)

```

Yet the path should be:

```
 /home/ricardo/Documents/UnrealProjects/DivisactionIntg2/ThirdParty/Divisaction/Libraries/libDivisaction.so

```

I ran

```
nm --demangle libDivisaction.so

```

And Divisaction::DTime::setTimeCalculator() appears with a T next to it.

The same error is still thrown.

If you have the time, I could upload the `.so` and you could try it out.

---

<div class="post-metadata">

**Author:** ![RicardoEPRodrigues](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ricardoeprodrigues/32/918672_2.png) [@RicardoEPRodrigues](https://forums.unrealengine.com/u/RicardoEPRodrigues)\
**Post date:** [June 29, 2017, 12:13am UTC](https://forums.unrealengine.com/t/cant-link-a-library/396690/8 "2017-06-29T00:13:20Z")

</div>

I know this is a bummer, but I really need to get it to work.

I ran nm on my lib and on the project lib and searched for setTimeCalculator function.

On my lib I get this:

```
0000000000051780 T _ZN11Divisaction5DTime17setTimeCalculatorESt10shared_ptrINS_15DTimeCalculatorEE

```

While on the project lib I get:

```
U _ZN11Divisaction5DTime17setTimeCalculatorENSt3__110shared_ptrINS_15DTimeCalculatorEEE

```

After doing a c++filt I see they differ very little, but they differ:

```
Divisaction::DTime::setTimeCalculator(std::shared_ptr<Divisaction::DTimeCalculator>)
Divisaction::DTime::setTimeCalculator(std::__1::shared_ptr<Divisaction::DTimeCalculator>)

```

How can I fix this?

---

<div class="post-metadata">

**Author:** ![RicardoEPRodrigues](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ricardoeprodrigues/32/918672_2.png) [@RicardoEPRodrigues](https://forums.unrealengine.com/u/RicardoEPRodrigues)\
**Post date:** [June 29, 2017, 2:44pm UTC](https://forums.unrealengine.com/t/cant-link-a-library/396690/9 "2017-06-29T14:44:04Z")

</div>

New update: I was able to correctly compile my lib with clang. libc++ and libc++abi.

Problem now is that UE4 tries to link my .so with old libs files. Like:

```
Engine/Binaries/ThirdParty/CEF3/Linux/libcef.so

```

How can I change it? Maybe I’ll try compiling it with the UE4 libs… but how?

---

<div class="post-metadata">

**Author:** ![RicardoEPRodrigues](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ricardoeprodrigues/32/918672_2.png) [@RicardoEPRodrigues](https://forums.unrealengine.com/u/RicardoEPRodrigues)\
**Post date:** [September 11, 2017, 12:06pm UTC](https://forums.unrealengine.com/t/cant-link-a-library/396690/10 "2017-09-11T12:06:14Z")

</div>

The only solution I found is to copy paste the code into a UE4 Plugin and compile it from there.

Basically, unless you have a extern “C” library (which I don’t), the library needs to be compiled using the same libraries as the engine. (aka compatibility issues…)
