How to resolve LNK2019 errors when using a static library encapsulating std::string in UE5

I’m trying to integrate gRPC as a plugin into a UE5 project. However, I encountered a linking error during compilation: error LNK2019 __std_find_last_trivial.

To investigate this issue, I specifically prepared three projects to test whether “a static library encapsulating std::string can reproduce this problem.” The attached TestLib.zip contains the static library files and a VS2022 project, with build parameters already configured.

vs_uselib.zip is a VS2022 project that uses TestLib, and it has been tested to confirm that the functions in the static library work correctly.

ue_uselib.zip is the UE5 project used for testing, and the relevant parameters for using TestLib have been configured in Build.cs. I used absolute paths. Colleagues who obtain the test projects will need to modify the library path accordingly.

The ue_uselib.zip project can reproduce the “error LNK2019 __std_find_last_trivial” issue.

I am aware that there are already some gRPC plugins available for UE, but I have decided to re-encapsulate a version that meets our specific requirements according to our needs. I hope to receive an official response soon.

Hello!

The problem is caused by using different settings\tools when generating the sample lib and the UE project. I was able to change the Testlib project so the generated library is compatible with the Engine environment. I think the main difference was the toolchain but I did change a few other things:

  • Toolchain: You can download older toolchain through the Visual Studio installer. I had to add the following group in Testlib.vcxproj to align the toolchain
  <PropertyGroup> 
    <VCToolsVersion Condition = "'$(VCToolsVersion)' == ''" >14.38.33130</VCToolsVersion> 
    <VCToolsRedistVersion Condition = "'$(VCToolsRedistVersion)' == ''" >14.38.33130</VCToolsRedistVersion>  
  </PropertyGroup>  
  • Windows SDK version: I changed the setting in the properties panel on the General tab. The proper version is 10.0.22621.0
  • C++ Language Standard: Unreal uses C++20 as default since 5.5. It can be change in the project properties panel on the General tab

I recommend making sure to always use the recommended toolchain and Windows SDK when moving to a new major release of the engine (5.5, 5.6...). The information can be obtained from Engine\Config\Windows\Windows_SDK.json. Look for the MainVersion attribute for the Windows SDK and PreferredVisualCppVersions for the toolchain. If there are multiple toolchain in the array, the first one is the version to use. Those are the what we used when we mastered the release and guaranteed to compile and link the engine. We cannot guarantee that other toolchains and SDKs are compatible with the engine.

I’m attaching an updated zip file that contains the modified project so you can generate a library that is compatible with Unreal 5.5.

Regarding the Unreal project, you can use the ModuleRules::ModuleDirectory member to create a relative path so the lib will always be found. In uselib.Build.cs:

//Original Hardcoded path
//PublicAdditionalLibraries.AddRange(new string[] { "F:/UE5Project/uselib/Source/uselib/TestLib.lib" });
 
//Updated relative path
PublicAdditionalLibraries.Add(Path.Combine(ModuleDirectory, "TestLib.lib"));
 
 

Regards,

Martin