Announcement

Collapse
No announcement yet.

Compiler Error (Linking Error)? Unresolved External Symbol

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Compiler Error (Linking Error)? Unresolved External Symbol

    Hey guys,

    can someone please explains a way to fix this compiler error? I've tried to look at some sources but I don't seems to get the answer.
    Is the problem lies in missing headers?

    What does linking error means?

    Click image for larger version

Name:	Untitled-1.jpg
Views:	1
Size:	156.0 KB
ID:	1141021

    I am very new at C++ and programming. Can I please get some help with detailed step?

    I tried to follow FPS game mode tutorial from https://wiki.unrealengine.com/First_...2B%2B_Tutorial

    I thought it would be a good start. I'm pretty sure I followed every single step as mentioned but in the end I got stuck in the first compiling step.

    Here is the code I changed according to the tutorial

    Code:
    #include "Shattered_Code.h"
    #include "Shattered_CodeGameMode.h"
    
    
    AShattered_CodeGameMode::AShattered_CodeGameMode(const class FPostConstructInitializeProperties& PCIP)
    	: Super(PCIP)
    {
    
    	Super::BeginPlay();
    	StartMatch();
    	if (GEngine)
    	{
    		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("HELLO WORLD"));
    	}
    }
    Code:
    #pragma once
    
    #include "GameFramework/GameMode.h"
    #include "FPSGame_Mode.generated.h"
    
    /**
     * 
     */
    UCLASS()
    class SHATTERED_CODE_API AFPSGame_Mode : public AGameMode
    {
    	GENERATED_UCLASS_BODY()
    
    	virtual void StartPlay() override; //at Start// 
    	
    	
    };
    Also I want to know where Start Play is derived from. Is it necessary to a certain header for StartPlay to work?
    Last edited by Mirai99; 11-20-2014, 07:45 AM.

    #2
    Super::BeginPlay() is a method declaration, you have to define it in the .cpp:

    AShattered_CodeGameMode::StartPlay()
    {
    Super::StartPlay();
    }

    Instead you call it in the Constructor via Super::BeginPlay() , I guess you got a mistake in the name there ? (BeginPlay vs StartPlay?)

    Comment


      #3
      Wups, Thanks for that. I place the method in the obvious wrong place. I will try to fix it and see how it goes

      Edit:

      I added the function below the constructor

      but I get this Error

      Error 1 error C2509: 'BeginPlay' : member function not declared in 'AShattered_CodeGameMode' D:\Unreal_Projects\Shattered_Prototype\Shattered_Code\Source\Shattered_Code\Shattered_CodeGameMode.cpp 16 1 Shattered_Code


      The code is as follow
      Code:
      // Fill out your copyright notice in the Description page of Project Settings.
      
      #include "Shattered_Code.h"
      #include "Shattered_CodeGameMode.h"
      
      
      AShattered_CodeGameMode::AShattered_CodeGameMode(const class FPostConstructInitializeProperties& PCIP)
      	: Super(PCIP)
      {
      
      	
      }
      
      
      void AShattered_CodeGameMode::BeginPlay()
      {
      	Super::BeginPlay();
      
      	StartMatch();
      
      	if (GEngine)
      	{
      		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("HELLO WORLD"));
      	}
      }
      How to declare a function??
      Last edited by Mirai99; 11-20-2014, 08:40 AM.

      Comment


        #4
        You have to declare a function in the .h file (the 2nd code snippet in your first post), like this:

        Code:
        virtual void StartPlay() override; //at Start//
        You declared STARTPLAY though, and if you write BeginPlay instead, you can use it in the .cpp file, like you just did:

        .cpp

        Code:
        // Fill out your copyright notice in the Description page of Project Settings.
        
        #include "Shattered_Code.h"
        #include "Shattered_CodeGameMode.h"
        
        
        AShattered_CodeGameMode::AShattered_CodeGameMode(const class FPostConstructInitializeProperties& PCIP)
        	: Super(PCIP)
        {
        
        	
        }
        
        
        void AShattered_CodeGameMode::BeginPlay()
        {
        	Super::BeginPlay();
        
        	StartMatch();
        
        	if (GEngine)
        	{
        		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("HELLO WORLD"));
        	}
        }
        Code:
        #pragma once
        
        #include "GameFramework/GameMode.h"
        #include "FPSGame_Mode.generated.h"
        
        /**
         * 
         */
        UCLASS()
        class SHATTERED_CODE_API AFPSGame_Mode : public AGameMode
        {
        	GENERATED_UCLASS_BODY()
        
        	virtual void BeginPlay() override; //at Start// 
        	
        	
        };
        I didn't test it, but that should work

        Comment


          #5
          Hmm It still gives me unresolved external symbol

          Sry to confuse you but I made a mistake on the placement.

          Ignore the Shattered_Code . I need to print a simple text from FPSGame_Mode Class

          This is the .cpp file

          Code:
          // Fill out your copyright notice in the Description page of Project Settings.
          
          #include "Shattered_Code.h"
          #include "FPSGame_Mode.h"
          #include "Engine.h"  
          
          AFPSGame_Mode::AFPSGame_Mode(const class FPostConstructInitializeProperties& PCIP)
          	: Super(PCIP)
          {
          
          }
          
          
          void AFPSGame_Mode::StartPlay()
          {
          	Super::StartPlay();
          
          	StartMatch();
          
          	if (GEngine)
          	{
          		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("HELLO WORLD"));
          	}
          }

          and this is the header

          Code:
          // Fill out your copyright notice in the Description page of Project Settings.
          
          #pragma once
          
          #include "GameFramework/GameMode.h"
          #include "FPSGame_Mode.generated.h"
          
          /**
           * 
           */
          UCLASS()
          class SHATTERED_CODE_API AFPSGame_Mode : public AGameMode
          {
          	GENERATED_UCLASS_BODY()
          
          	virtual void StartPlay() override; //at Start// 
          	
          	
          };
          I think this should be fine, and a simple task. however I still get this error
          Code:
          Error	1	error LNK2001: unresolved external symbol "public: virtual void __cdecl AShattered_CodeGameMode::StartPlay(void)" (?StartPlay@AShattered_CodeGameMode@@UEAAXXZ)	D:\Unreal_Projects\Shattered_Prototype\Shattered_Code\Intermediate\ProjectFiles\Shattered_CodeGameMode.cpp.obj	Shattered_Code

          Comment


            #6
            Wups... I declared another StartPlay() in another header file... It's working now. Thank you very much!

            Comment

            Working...
            X