Linker error with C++ std lib on Linux

I am trying to include a library of my own functions in my Unreal project. I can successfully link the library dynamically, however attempting to use any functions which utilise std::string and other parts of the standard library cause a linker error ( undefined reference). Linking statically causes a similar error, regardless of whether the functions are used or not.

The library is built with Qt Creator (no Qt libraries though), and is linked against libstdc++ (tested with both clang and g++).

As far as I can tell, Unreal is trying to use the packaged libc++ instead of libstdc++. Searching online suggests setting a variable called UE4_LINUX_USE_LIBCXX to 0 somewhere, but I cannot find any details on how to do this.

Is this the correct approach to be taking, and if so, how/where do I set this variable?

The best approaches to take (in order of preference):

  1. rebuild your library to use libc++
  2. add a dependency on libstdc++ to your module (PublicAdditionalLibraries.Add(“stdc++”))
  3. set the environment variable UE4_LINUX_USE_LIBCXX to 0 and recompile Unreal.

Rationale: if you’re planning to redistribute the resulting Unreal project across Linux distros, you may run into problems with compatibility of libstdc++.so. You cannot bundle libstdc++.so with your Unreal project or link it statically (at least without consulting the lawyer), so you are better off using libc++ which can be freely bundled.