Can't link a Library

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?

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(...)

)

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.

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

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.

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)

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.

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?

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?

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…)