Unresolved external in FHTTPModule

I just can’t figure this one out. All the threads about HTTP seem to be quite old. I’m on 4.10.

2> [14/14] Link UE4Editor-FOTBS-Win64-DebugGame.dll
2> Creating library D:\UnrealEngine4\Projects\FOTBS\Intermediate/Build/Win64\UE4Editor\DebugGame\UE4Editor-FOTBS-Win64-DebugGame.lib and object D:\UnrealEngine4\Projects\FOTBS\Intermediate/Build/Win64\UE4Editor\DebugGame\UE4Editor-FOTBS-Win64-DebugGame.exp
2>FOTBSHTTP.cpp.obj : error LNK2001: unresolved external symbol “public: virtual bool __cdecl FHttpModule::Exec(class UWorld *,wchar_t const *,class FOutputDevice &)” (?Exec@FHttpModule@@UEAA_NPEAVUWorld@@PEB_WAEAVFOutputDevice@@@Z)
2>FOTBSHTTP.cpp.obj : error LNK2019: unresolved external symbol “public: virtual class TSharedRef __cdecl FHttpModule::CreateRequest(void)” (?CreateRequest@FHttpModule@@UEAA?AV?$TSharedRef@VIHttpRequest@@$0A@@@anonymous_user_9674a66c) referenced in function “public: void __cdecl UFOTBSHTTP::MakeRequest(void)” (?MakeRequest@UFOTBSHTTP@@QEAAXXZ)
2>FOTBSHTTP.cpp.obj : error LNK2001: unresolved external symbol “private: virtual void __cdecl FHttpModule::StartupModule(void)” (?StartupModule@FHttpModule@@EEAAXXZ)
2>FOTBSHTTP.cpp.obj : error LNK2001: unresolved external symbol “private: virtual void __cdecl FHttpModule::ShutdownModule(void)” (?ShutdownModule@FHttpModule@@EEAAXXZ)
2>D:\UnrealEngine4\Projects\FOTBS\Binaries\Win64\UE4Editor-FOTBS-Win64-DebugGame.dll : fatal error LNK1120: 4 unresolved externals

Looks like you aren’t including the http module into your project. I’m not sure what the exact dependency is, but check that you have this somewhere. In your MyGame.build.cs file.

	PublicDependencyModuleNames.AddRange(
		new string[] {
			...
			"HTTP",
                        ...

You could touch one of the http cpp files (add a compiler error) and see if it catches it. I suspect it won’t.

1 Like

Hi Josh, thanks for your reply. I included the dependency module and no change, still unresolved. And of course, adding compiler error into the HttpModule.cpp is not picked up by the compiler, even after dependency module inclusion.
Basically - no change at all.

If you are making a C++/Native application and not a fully blueprint game the fact that the forced compiler error isn’t being picked up means something isn’t right about the dependency checking or your build.cs file. Which certainly continue to cause link errors.

Can you look at your link.exe command line and see if the module is being referenced there? Or in any of the build command output?

I’d have to look into the UBT code to see where you could output some debugging to see what modules your project is attempting to bring in.

Thank you for the suggestion. I’m on VS2015 so I don’t see the link.exe command line. Is there a way for me to see it ? I’ve included “HTTP” in both Build and Target.cs files

Build.cs

using UnrealBuildTool;

public class FOTBS : ModuleRules
{
public FOTBS(TargetInfo Target)
{
PublicDependencyModuleNames.AddRange(new string[] { “Core”, “CoreUObject”, “Engine”, “InputCore” , “HTTP” });
}
}

FOTBSHTTP.h

#pragma once

#include “FOTBS.h”

#include “Runtime/Online/HTTP/Public/Http.h”

#include “FOTBSHTTP.generated.h”

UCLASS()
class UFOTBSHTTP : public UObject
{
GENERATED_BODY()

public:
UFOTBSHTTP();

void MakeRequest();

void OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);

};

FOTBSHTTP.cpp

#include “FOTBS.h”

#include “FOTBSHTTP.h”

#include “Public/FOTBSHUD.h”

#include “Runtime/Online/HTTP/Public/HttpModule.h”

#include “Runtime/Online/HTTP/Public/Http.h”

UFOTBSHTTP::UFOTBSHTTP() {

}

void UFOTBSHTTP::MakeRequest() {

FHttpModule httpmodule = FHttpModule::Get();
TSharedRef<IHttpRequest> HttpRequest = httpmodule.CreateRequest();
HttpRequest->SetVerb("GET");
HttpRequest->SetURL(FString("http://myserver.com"));
HttpRequest->OnProcessRequestComplete().BindUObject( this, &UFOTBSHTTP::OnResponseReceived );
HttpRequest->ProcessRequest();

}

void UFOTBSHTTP::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful) {

FString responseData = Response->GetContentAsString();

if (!bWasSuccessful)
{
	UE_LOG(LogTemp, Error, TEXT("Response was invalid! Please check the URL."));
	return;
}

}

While I spent the last 25 years coding, the last time I was working with C++ was in DOS4GW times and the Windows syntax is certainly new to me so I keep spending time looking for answers. Would you by any chance be able to recommend good read about the logic behind modules and dependencies and maybe Visual Studio-specific considerations?

Try upping the verbosity of logging under Tools:Options:ProjectsAndSolutions:BuildAndRun
MSDN Link

I’m not familiar with your build flow. Internally we have Incredibuild and UnrealBuildTool (UBT) will generate a file that describes all the cl.exe and link.exe operations. Vanilla VS20xx will output a log as well.

I believe UBT ultimately uses MSBuild.exe to build things in your case, so there should be a log file somewhere with the output. I’m sorry I’m in “hand wavy” mode at the moment.

Add “-verbose” and/or “-xgeexport” to the compiler settings. They are under the NMake section of VS20xx. Right click on your project settings, Properties, Configuration Properties, NMake. You’ll see the Build and Rebuild command lines.

As for “good reads”, Unreal does a bunch of trickery with modules, but ultimately they are just DLLs. It’s more a Windows consideration than a VS consideration. Unreal/UBT handles all the __declspec(dllexport) and __declspec(dllimport) magic via our MODULENAME_API define.
If you search for the variable ModuleApiDefine in our .cs files (UEBuildModule.cs), you’ll see how that magic works. That converts to the right thing in WindowsPlatform.h (or any of the other platforms)

In this case I’m expecting the HTTP_API to be defined, which I believe it is, but then the .lib/.dll are not being included and thus the link error.

Upvoted: I likewise encountered this issue working with HTTPModule in custom 4.20 engine build, still trying to rectify the problem.

Did you find an answer to this? I have the same problem in 4.20 (installed build). I did add “HTTP” to the Build.cs file. But it still fails.

edit: It must be a problem with my project (or the fact that I am trying to use the HttpModule in a plugin module). If I create a new project and add a C++ class with the HttpModule, it compiles fine.

This did the trick for me

Changing this:

FHttpModule Http = FHttpModule::Get();

To this:

FHttpModule * Http = &FHttpModule::Get();

Resolved the linking error for me.

6 Likes