Using the UE5.4 built-in Libcurl.lib in a plugin (w/ no unresolved external references)

Here’s another example of using a third-party library in a plugin. In this case, the built-in (to UE5.4) third-party static libcurl.lib is added to a plugin. Note that simply using PublicAdditionalLibraries.Add() is not enough to satisfy the linker during compilation nor does it initialize libcurl correctly. Make the following addition to PluginName.Build.cs:

    PublicDefinitions.Add("WITH_LIBCURL=1");  // This is required
    PublicDefinitions.Add("CURL_STATICLIB=1");  // This is required when using static libcurl.lib
    string LibCurlPath = Target.UEThirdPartySourceDirectory + "libcurl/8.4.0/include/curl/";
    PublicSystemIncludePaths.Add(LibCurlPath); // located in the UE5.4 engine (not the project)   PublicAdditionalLibraries.Add(Target.UEThirdPartySourceDirectory+"libcurl/8.4.0/lib/Win64/Release/libcurl.lib");
    AddEngineThirdPartyPrivateStaticDependencies(Target, new string[]
		{
			"nghttp2",
			"OpenSSL",
			"zlib"
		});  // libcurl.lib has additional dependencies (from libcurl.Build.cs)
    PublicIncludePaths.Add($"{LibCurlPath}");

In the StartupModule(), or at the beginning of your code, add:

curl_global_init(CURL_GLOBAL_DEFAULT);

In the ShutdownModule(), or at the end of your code, add:

curl_global_cleanup();

These changes will solve any “unresolved external reference” errors and initialize/shutdown libcurl.