Description

Adding a cable component to a custom code class will result in a build failure in Visual Studio unless the Cable Component's source code is modified to include CABLECOMPONENT_API.

ANSWERHUB:
https://answers.unrealengine.com/questions/226113/using-cablecomponent-in-c-gives-you-linker-error.html

Steps to Reproduce
  1. Create a new project using the first person template, no starter content.
  2. Add a new Actor code class to the project.
  3. Open the Build.cs file for your project and add the following lines of code:
    PrivateDependencyModuleNames.AddRange(new string[] { "CableComponent" });
    PrivateIncludePathModuleNames.AddRange(new string[] { "CableComponent" });
    
  4. In the header file for the code class created in step 2, add the following code:
    #include "CableComponent.h"
    
    UPROPERTY(Category = "Cable", EditAnywhere, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"))
    UCableComponent* cable;
    
  5. In the source file for the class created in step 2, add the following code to the constructor:
    cable = ObjectInitializer.CreateDefaultSubobject<UCableComponent>(this, TEXT("cable"));
  6. Build the project in Visual Studio.

RESULT:
The build fails with the following LNK2019 error message:

error LNK2019: unresolved external symbol "private: static class UClass * __cdecl UCableComponent::GetPrivateStaticClass(wchar_t const *)" (?GetPrivateStaticClass@UCableComponent@@CAPEAVUClass@@PEB_W@Z) referenced in function "public: class UCableComponent * __cdecl FObjectInitializer::CreateDefaultSubobject<class UCableComponent>(class UObject *,class FName,bool)const " (??$CreateDefaultSubobject@VUCableComponent@@@FObjectInitializer@@QEBAPEAVUCableComponent@@PEAVUObject@@VFName@@_N@Z)

EXPECTED:
The project builds successfully.

WORKAROUND:
In the CableComponent.h file, change the line class UCableComponent : public UMeshComponent to class CABLECOMPONENT_API UCableComponent : public UMeshComponent

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-15620 in the post.

1
Login to Vote

Fixed
ComponentUE - Gameplay
Affects Versions4.7.64.9
Target Fix4.8
Fix Commit2552308
Release Commit2552533
CreatedMay 14, 2015
ResolvedMay 15, 2015
UpdatedApr 27, 2018
View Jira Issue