ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM) cause link failre.

I was making a simple Online Chess Game, which requires local IP address when connecting. I know that you can get the IP by using:


TSharedRef<FInternetAddr> localIp = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->GetLocalHostAddr(*GLog, canBind);

But wherever I write “ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)”, it gives me link failure LNK2019 like this:

The “NetworkUtils” is where I put the invoke “ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)”, written in a static UFUNCTION.
(I have also tested this “Get” at other location, all results in the same error)

Is this a bug, or is there some module I need to write in Build.target.cs? (I haven’t found any in the documenton)

I guess you need to add


PublicDependencyModuleNames.Add("Sockets"); 

to your ProjectName.Build.cs

If you look at the ISocketSubsystem declaration in the header, you will find:


class SOCKETS_API ISocketSubsystem

The preprocessor macro often already includes the module-name you have to add to your build.cs file.

The related runtime module build.cs is “Sockets.Build.cs”

1 Like

OMG, Thank U so much, that actually solved my problem!
I always have a problem with “XX.build.cs” and “XX.Target.cs”, I tried to add “sockets” in “XX.Target.cs” and it won’t work…

Thanks again!