How to add groomcomponent via c++ and attach it to skeletal mesh

I had this problem for UE5.2, but regenerating project files didn’t solve it.

Instead I followed:
NiagaraDataInterfacePhysicsAsset.h and GroomComponent.h in Unreal 5.1

I solved it by adding both “HairStrandsCore” and “Niagara” to “PublicDependencyModuleNames” in my .Build.cs file.