Sunday 16 June 2019

header - LNK2019 error with functions used in main with Visual Studio 2012 C++



I receive the following error:




1>main.obj : error LNK2019: unresolved external symbol "void __cdecl
setup(void)" (?setup@@YAXXZ) referenced in function _main 1>main.obj :

error LNK2019: unresolved external symbol "void __cdecl display(void)"
(?display@@YAXXZ) referenced in function _main
1>C:\code\Project1\Debug\Project1.exe : fatal error LNK1120: 2
unresolved externals




How do i resolve this?



Here is the main class, where the functions are used:




#include "interface.h"
using namespace std;

int main(){
setup();
display();
system("pause");
return 0;
}



Here is interface.cpp



#include 
#include
#include "interface.h"
using namespace std;
class ui{
void setup(){
options[0][0]="Hello";

options[1][0]="Hello";
options[2][0]="Hello";
options[3][0]="Hello";
options[4][0]="Hello";
options[5][0]="Hello";
options[6][0]="Hello";
options[7][0]="Hello";
options[8][0]="Hello";
options[9][0]="Hello";
}

void changeOption(int whatOption, string whatText,
string prop1, string prop2, string prop3, string prop4, string prop5){
options[whatOption][0]=whatText;
options[whatOption][1]=prop1;
options[whatOption][2]=prop2;
options[whatOption][3]=prop3;
options[whatOption][4]=prop4;
options[whatOption][5]=prop5;
}
void display(){

for(int x=0;x<9;x++){
cout< }
}
};


and here is interface.h



#include 

//#include
using namespace std;
#ifndef INTERFACE_H_INCLUDED
#define INTERFACE_H_INCLUDED
void setup();
extern string options[10][6];
void changeOption(int whatOption, string whatText, string prop1, string prop2, string prop3, string prop4, string prop5);
void display();
#endif INTERFACE_H


Answer



You declare these as global functions.



However, your implementation defines them inside of class ui{.



You can remove the class ui{ and matching closing parenthesis and it should work correctly.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...