0

So right now I'm having this issue:
"Unresolved external symbol "public: void__thiscall canoid::getinput(void)" (?Getinput@Canoid@@QAEXXZ) referenced in function _main" in the programming language c++
I need help fixing this I tried to look for how to fix this issue online and didn't find any. The error code is LNK2019 Here is the Coding Language sorry for the messy code :(

Canoid.h

#include <iostream>
#include <math.h>
#include <vector>
#include <string>
#include <algorithm>
#include <conio.h>
using namespace std;

string error_output = "";
bool AllowToInit = true;
class Canoid {

public:

    // Init(); is used for Used for initlizazing the Canoid, InitDone checks if initiated
     void Init();
     bool InitDone = false;
     // Input- Gets the Input of the Input
     string Input;
     // stops Init(); Funciton
     void Uninitiated();

     // Gets ASCIITABLE (127)
     void GetAsciiTable();
     // Definition of key input;

     // A-Z
     #define CANOID_A 65;
     #define CANOID_B 66;
     #define CANOID_C 67;
     #define CANOID_D 68;
     #define CANOID_E 69;
     #define CANOID_F 70;
     #define CANOID_G 71;
     #define CANOID_H 72;
     #define CANOID_I 73;
     #define CANOID_J 74;
     #define CANOID_K 75;
     #define CANOID_L 76;
     #define CANOID_M 77;
     #define CANOID_N 78;
     #define CANOID_O 79;
     #define CANOID_P 80;
     #define CANOID_Q 81;
     #define CANOID_R 82;
     #define CANOID_S 83;
     #define CANOID_T 84;
     #define CANOID_U 85;
     #define CANOID_V 86;
     #define CANOID_W 87;
     #define CANOID_X 88;
     #define CANOID_Y 89;
     #define CANOID_Z 90;
         //END OF A-Z

     // Lowercase Alphabets [a-z]
     #define CANOID_a 97
     #define CANOID_b 98
     #define CANOID_c 99
     #define CANOID_d 100
     #define CANOID_e 101
     #define CANOID_f 102
     #define CANOID_g 103
     #define CANOID_h 104
     #define CANOID_i 105 
     #define CANOID_j 106
     #define CANOID_k 107
     #define CANOID_l 108
     #define CANOID_m 109
     #define CANOID_n 110
     #define CANOID_o 111
     #define CANOID_p 112
     #define CANOID_q 113
     #define CANOID_r 114
     #define CANOID_s 115
     #define CANOID_t 116
     #define CANOID_u 117
     #define CANOID_v 118
     #define CANOID_w 119
     #define CANOID_x 120
     #define CANOID_y 121
     #define CANOID_z 122
      // End Lowercase Alphabets [a-z]
     #define CANOID_ESCAPE 27  // escape key



     // End of Definition of CANOID Input

     // Key Func
     int key();

     // Input
     void GetInput();

     // CANOID_GET_ERROR is used for getting error.
     #define CANOID_GET_ERROR error_output;
};

// Functions

void Canoid::Init() {

    if (AllowToInit == true) {
        InitDone = true;
    }
    else {
        error_output = "AllowToInit has been disabled.";
    }
}

void Canoid::Uninitiated() {
    exit(-0);
}

void Canoid::GetAsciiTable() {
    if (InitDone == true) {

        // Get's the ASCII Table.
        for (int AsciiTableNo = 0; AsciiTableNo< 127; AsciiTableNo++) {
            cout << char(AsciiTableNo);
        }
    }
    else {
        error_output = "you have not initiated the program yet.";
    }
}

// key values
int Canoid::key() {
    if (InitDone == true) {
        char key = _getch();
        return key;
    }
    else {
        error_output = "you have not initiated the program yet.";
        return 0;
    }
}

Canoid_UserInput.h

#include "Canoid.h"

Canoid canoid;

void Canoid::GetInput() {

    if (canoid.InitDone == true) {
        // caps
        if (canoid.key() == CANOID_a) {
            canoid.Input = canoid.Input + "a";
        }
        if (canoid.key() == CANOID_b) {
            canoid.Input = canoid.Input + "b";
        }if (canoid.key() == CANOID_c) {
            canoid.Input = canoid.Input + "c";
        }if (canoid.key() == CANOID_d) {
            canoid.Input = canoid.Input + "d";
        }if (canoid.key() == CANOID_e) {
            canoid.Input = canoid.Input + "e";
        }if (canoid.key() == CANOID_f) {
            canoid.Input = canoid.Input + "f";
        }if (canoid.key() == CANOID_g) {
            canoid.Input = canoid.Input + "g";
        }if (canoid.key() == CANOID_h) {
            canoid.Input = canoid.Input + "h";
        }if (canoid.key() == CANOID_i) {
            canoid.Input = canoid.Input + "i";
        }if (canoid.key() == CANOID_j) {
            canoid.Input = canoid.Input + "j";
        }if (canoid.key() == CANOID_k) {
            canoid.Input = canoid.Input + "k";
        }if (canoid.key() == CANOID_l) {
            canoid.Input = canoid.Input + "l";
        }if (canoid.key() == CANOID_m) {
            canoid.Input = canoid.Input + "m";
        }if (canoid.key() == CANOID_n) {
            canoid.Input = canoid.Input + "n";
        }if (canoid.key() == CANOID_o) {
            canoid.Input = canoid.Input + "o";
        }if (canoid.key() == CANOID_p) {
            canoid.Input = canoid.Input + "p";
        }if (canoid.key() == CANOID_q) {
            canoid.Input = canoid.Input + "q";
        }if (canoid.key() == CANOID_r) {
            canoid.Input = canoid.Input + "r";
        }if (canoid.key() == CANOID_s) {
            canoid.Input = canoid.Input + "s";
        }if (canoid.key() == CANOID_t) {
            canoid.Input = canoid.Input + "t";
        }if (canoid.key() == CANOID_u) {
            canoid.Input = canoid.Input + "u";
        }if (canoid.key() == CANOID_v) {
            canoid.Input = canoid.Input + "v";
        }if (canoid.key() == CANOID_w) {
            canoid.Input = canoid.Input + "w";
        }if (canoid.key() == CANOID_x) {
            canoid.Input = canoid.Input + "x";
        }if (canoid.key() == CANOID_y) {
            canoid.Input = canoid.Input + "y";
        }if (canoid.key() == CANOID_z) {
            canoid.Input = canoid.Input + "z";
        }
    }
    else {
        error_output = "you have not initiated the program yet.";
    }
}

Source.cpp

#include <iostream>
#include "Canoid.h"
using namespace std;

int value = 0;
int main() {
    Canoid canoid;
    canoid.Init();
    cout << CANOID_GET_ERROR;



    //=================================
    while (true) {
        //if (canoid.key() == CANOID_ESCAPE) {
        //  value++;
        //  cout << " Pause " << endl;
        //  cout << " Press ESC to resume" << endl;

        //}

        //if (canoid.key() == CANOID_ESCAPE && value == 1) {
        //  system("cls");
        //  value = 0;
        //}

        canoid.GetInput();
        cout << canoid.Input;
    }
    //=================================
}

This is the output for the program

1>------ Build started: Project: Canoid, Configuration: Debug Win32 ------
1>Source.obj : error LNK2019: unresolved external symbol "public: void __thiscall Canoid::GetInput(void)" (?GetInput@Canoid@@QAEXXZ) referenced in function _main
1>C:\Users\NAME\source\repos\Canoid\Debug\Canoid.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "Canoid.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108

1 Answers1

0

Canoid_UserInput.h was never included, so the function was never compiled and cannot be found by the linker.

Solution:

While you could include Canoid_UserInput.h, this file has the look of a cpp source file, so it should be named and handled differently. Change the name of Canoid_UserInput.h to Canoid_UserInput.cpp. Ensure Canoid_UserInput.cpp is added to Visual Studio's list of files to be built in the Solution Explorer (usually the right-most window pane) and rebuild.

Community
  • 1
  • 1
user4581301
  • 33,082
  • 7
  • 33
  • 54