How can I resolve the linker errors "LNK2019" and "LNK1120" when using RHIGetAvailableResolutions?

I’m trying to get a list of supported resolutions to show on the options menu. To this end, I used the function RHIGetAvailableResolutions (example usage in UnrealEngine.cpp UEngine::HandleDumpAvailableResolutionsCommand), but got linker errors:

1>  link.exe UE4Editor-ShooterGame-Win64-DebugGame.dll
1>     Creating library D:\UnrealEngine\ShooterGame\Intermediate\Build\Win64\ShooterGameEditor\DebugGame\UE4Editor-ShooterGame-Win64-DebugGame.lib and object D:\UnrealEngine\ShooterGame\Intermediate\Build\Win64\ShooterGameEditor\DebugGame\UE4Editor-ShooterGame-Win64-DebugGame.exp
1>Module.ShooterGame.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) bool __cdecl RHIGetAvailableResolutions(class TArray<struct FScreenResolutionRHI,class FDefaultAllocator> &,bool)" (__imp_?RHIGetAvailableResolutions@@YA_NAEAV?$TArray@UFScreenResolutionRHI@@VFDefaultAllocator@@@@_N@Z) referenced in function "public: void __cdecl FShooterOptions::Construct(class APlayerController *)" (?Construct@FShooterOptions@@QEAAXPEAVAPlayerController@@@Z)
1>D:\UnrealEngine\ShooterGame\Binaries\Win64\UE4Editor-ShooterGame-Win64-DebugGame.dll : fatal error LNK1120: 1 unresolved externals

Any ideas?

PS: I’m not using the DumpAvailableResolutions console command because it’s not defined for shipping/release builds.

The solution is to add “RHI” to PublicDependencyModuleNames, in the Myprojectname.Build.cs file.

2 Likes