Getting linker errors when using the std library

Anytime I attempt to use the std library in UE5 I’m getting unresolved external symbol errors. For example, on a new project if I instantiate a std::string in an Actor I get the following linker error:

error LNK2001: unresolved external symbol "void __cdecl std::_Xlength_error(char const *)" (?_Xlength_error@std@@YAXPEBD@Z)

Another example, if I attempt to instantiate a std::mutex and std::unique_lock I get:

MyActor.cpp.obj : error LNK2019: unresolved external symbol _Mtx_init_in_situ referenced in function "protected: virtual void __cdecl AMyActor::BeginPlay(void)" (?BeginPlay@AMyActor@@MEAAXXZ)
MyActor.cpp.obj : error LNK2019: unresolved external symbol _Mtx_destroy_in_situ referenced in function "public: __cdecl std::mutex::~mutex(void)" (??1mutex@std@@QEAA@XZ)
MyActor.cpp.obj : error LNK2019: unresolved external symbol _Mtx_lock referenced in function "protected: virtual void __cdecl AMyActor::BeginPlay(void)" (?BeginPlay@AMyActor@@MEAAXXZ)
MyActor.cpp.obj : error LNK2019: unresolved external symbol _Mtx_unlock referenced in function "protected: virtual void __cdecl AMyActor::BeginPlay(void)" (?BeginPlay@AMyActor@@MEAAXXZ)
MyActor.cpp.obj : error LNK2019: unresolved external symbol "void __cdecl std::_Throw_C_error(int)" (?_Throw_C_error@std@@YAXH@Z) referenced in function "protected: virtual void __cdecl AMyActor::BeginPlay(void)" (?BeginPlay@AMyActor@@MEAAXXZ)

Is this intended behavior or am I missing something in my dev environment? I’m trying to develop a plugin which builds against a static library that uses the std library, and UBT failing to find std lib symbols is blocking me unfortunately.

I’m on a Windows machine running Windows 10. I’ve tested using UE 5.0 and 5.1, as well as on Windows 11. I’ve manually downloaded the 2010, 2012, 2013, and 2015 Visual C++ CRT’s with no luck.

Hi michael_aqueduct,

Check this forum post here for some good details about stdlib, including a post from Tim Sweeney…

Thanks for the reply. I understand that it isn’t recommended to use STL containers within UE5. However, is it true that you’re not able to use any STL container at all without getting stdlib linker errors? From speaking with colleagues they are able to build with UBT when using STL containers just fine, so I think my dev setup is incorrect

To be more specific with what I’m trying to do, I’m trying to integrate a pre-built third-party library that uses the std library. When I link against this pre-built static library in my module I get several linker errors for std methods. This led me to try to use any STL container in my project and I still get linker errors, which seems strange

You should be able to compile ok using basic stdlib things like std::string and std::map - I’ve compiled ok with them in the past.

If you’ve got some libs or DLLs built using older versions of VS it could have problems with incompatible stdlib’s - that could be an issue.

Also, those errors are indicating the CRT (CommonRunTime) is not being included:

What’s strange is I’m unable to build the main project module using UBT if I use any of the stdlib containers (ex. std::string). This leads me to think that UBT is unable to find the CRT. Do you know of any way to check that UBT is able to find stdlib?

I’m just building through VS, so maybe there is something specific to the UBT - while having a look around I found this article which was quite informative, it highlights near the bottom about the problems with third-party-stdlib-sharing:

But doesn’t offer a solution for this.

Does it work ok with stdlib if you build from a new simple project built in VS? If that fails too - it’s a good indication you’ll be needing to try and reinstall the lastest CRT…

Thanks for the link, I’ve actually already read that article. It was super informative on understanding ABI issues when integrating dynamic third-party libraries. However, I’m hitting linker issues when compiling the module itself using UBT

From your suggestion I’ve tried to build the module from VS directly and it appears to build even if I’m using STL containers! I can even modify the file and then later build using live coding and I no longer get any linker issues. Strangely enough it seems like I only get std linker issues if I don’t build within VS at all, but only trigger the build by pressing ctrl + alt + f11. Do you usually build your modules directly from within VS or do you also use the ctrl + alt + f11 shortcut while UE5 is running?

To be more clear the steps to repro the issue for me are:

  1. create new C++ project
  2. create Actor within main project module
  3. instantiate a std::string in the Actor (ex. in the BeginPlay() method)
  4. press ctrl + alt + f11 to trigger build
  5. observe linker issues with unresolved std symbols

To fix the linker issues, I close UE5 and then trigger a build directly from within VS (ctrl + b). This seems to also trigger UBT (since the VS sln was created by UE), but this time the build passes. I can then make modifications and compile using ctrl + alt + f11 while UE5 is running and it seems to build fine.

Need to test further when linking against my static library, but it seems like triggering a build from within VS while UE5 isn’t running causes UBT to be able to find the std CRT.

I’m old-school, I almost always build from VS with UE closed.

I just went through your steps and also got link errors - closed UE and built from VS and it worked.

Looks like a LiveCoding thing…

1 Like

Appreciate you taking the time to repro - super weird that this is the behavior of live coding. Marking this as resolved as the workaround is to ensure building through VS first.

1 Like

I wouldn’t mark this as resolved. In UE5.3 the same issue exists, but, you can’t work around it by closing the UE Editor. When you Rebuild your Project it builds fine but doing a normal Build fails with the same error.