Error LNK2019 & LNK1120

I continually get two errors mentioned in the title. I will post my code setup below and maybe someone can help me debug this issue. I shortened down quite a bit let me know if you need any additional info ( i didnt just wanna copy and paste all the code) Thanks in advance!


maindriver.cpp
1
2
#include structs.h
function(name, num1, num2, num3, eol, outputFile, pipeType, pipesize); // call function from main 


Structs.h holds my function prototypes
1
2
bool check(float num1, float num2, string pipeType, int pipesize); 
void function(char name[32], float num1, float num2, float num3, char eol[16], ostream &outputFile, string pipeType, int pipesize)


Function.cpp is a function that calls another function called check
1
2
3
4
5
6
7
// include structs.h
void function(char name[32], float num1, float num2, float num3, char eol[16], ostream &outputFile, string pipeType, int pipesize)
{
	bool flag = true;

	flag = check(num1, num2, pipeType, pipesize); // call my check function


check. cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include structs.h
bool check(float num1,float num2, int pipesize, string pipeType)
{
const float pi = 3.14159265358979;
    int div = 180;
	float value;
    bool valCheck = true;
	struct EMT
	{
		int pipesizeEmt;
		float bendRadiusEmt;
		float shoeDimensionEmt;
		float conduitDimensionEmt;
		float tailEmt;
	};
	EMT myemt[10][5] =
	{ 12,  5.883, 2.973, 0.530, 48.000,
		34, 6.000, 2.480, 0.692, 48.000,
		100, 7.000, 2.990, 0.872, 48.000,
		114, 8.500, 3.662, 1.133, 46.500,
		112, 8.500, 3.662, 1.305, 46.500,
		200, 9.250, 3.610, 1.648, 46.500,
		212, 12.000, 4.180, 2.156, 46.500,
		300, 16.000, 7.544, 2.625, 53.750,
		312, 18.625, 7.518, 3.000, 53.750,
		400, 20.875, 7.277, 3.375, 53.750
	};
struct RIGID
	{
		int pipesizeR;
		float bendRadiusR;
		float shoeDimensionR;
		float conduitDimensionR;
		float tailR;

	};
	RIGID myrigid[10][5] =
	{ 12,  5.950, 2.562, 0.875, 48.000,
		34, 6.937, 3.264, 0.875, 48.000,
		100, 7.000, 3.434, 1.165, 48.000,
		114, 8.500, 4.111, 1.285, 48.000,
		112, 8.500, 4.239, 1.530, 48.000,
		200, 9.000, 4.314, 1.781, 48.000,
		212, 12.000, 4.180, 2.000, 46.500,
		300, 16.000, 7.544, 2.000, 53.750,
		312, 18.625, 7.518, 2.500, 53.750,
		400, 20.875, 7.277, 2.500, 53.750
	};
if (pipeType == "EMT")
	{
		switch (pipesize)
		{
		case 12:
			value = (((num1)) + (myemt[0][1].bendRadiusEmt*(num2*pi / div))) + myemt[0][4].tailEmt;
			break;
		case 34:
			value = (((num1)) + (myemt[1][1].bendRadiusEmt*(num2*pi / div))) + myemt[1][4].tailEmt;
			break;
		case 100:
			value = (((num1)) + (myemt[2][1].bendRadiusEmt*(num2*pi / div))) + myemt[2][4].tailEmt;
			break;
		case 114:
			value = (((num1)) + (myemt[3][1].bendRadiusEmt*(num2*pi / div))) + myemt[3][4].tailEmt;
			break;
		case 112:
			value = (((num1)) + (myemt[4][1].bendRadiusEmt*(num2*pi / div))) + myemt[4][4].tailEmt;
			break;
		case 200:
			value = (((num1)) + (myemt[5][1].bendRadiusEmt*(num2*pi / div))) + myemt[5][4].tailEmt;
			break;
		case 212:
			value = (((num1)) + (myemt[6][1].bendRadiusEmt*(num2*pi / div))) + myemt[6][4].tailEmt;
			break;
		case 300:
			value = (((num1)) + (myemt[7][1].bendRadiusEmt*(num2*pi / div))) + myemt[7][4].tailEmt;
			break;
		case 312:
			value = (((num1)) + (myemt[8][1].bendRadiusEmt*(num2*pi / div))) + myemt[8][4].tailEmt;
			break;
		case 400:
			value = (((num1)) + (myemt[9][1].bendRadiusEmt*(num2*pi / div))) + myemt[9][4].tailEmt;
			break;
		}
	}
	else if (pipeType == "RIGID")
	{
		switch (pipesize)
		{
		case 12:
			value = (((num1)) + (myrigid[0][1].bendRadiusR*(num2*pi / div))) + myrigid[0][4].tailR;
			break;
		case 34:
			value = (((num1)) + (myrigid[1][1].bendRadiusR*(num2*pi / div))) + myrigid[1][4].tailR;
			break;
		case 100:
			value = (((num1)) + (myrigid[2][1].bendRadiusR*(num2*pi / div))) + myrigid[2][4].tailR;
			break;
		case 114:
			value = (((num1)) + (myrigid[3][1].bendRadiusR*(num2*pi / div))) + myrigid[3][4].tailR;
			break;
		case 112:
			value = (((num1)) + (myrigid[4][1].bendRadiusR*(num2*pi / div))) + myrigid[4][4].tailR;
			break;
		case 200:
			value = (((num1)) + (myrigid[5][1].bendRadiusR*(num2*pi / div))) + myrigid[5][4].tailR;
			break;
		case 212:
			value = (((num1)) + (myrigid[6][1].bendRadiusR*(num2*pi / div))) + myrigid[6][4].tailR;
			break;
		case 300:
			value = (((num1)) + (myrigid[7][1].bendRadiusR*(num2*pi / div))) + myrigid[7][4].tailR;
			break;
		case 312:
			value = (((num1)) + (myrigid[8][1].bendRadiusR*(num2*pi / div))) + myrigid[8][4].tailR;
			break;
		case 400:
			value = (((num1)) + (myrigid[9][1].bendRadiusR*(num2*pi / div))) + myrigid[9][4].tailR;
			break;
		}
// do some more stuff and then
//return bool
}



Last edited on
You say you get the errors "mentioned in the title". But you don't mention any errors in the title. You just mention two arbitrary numbers which means that you expect us to look up the meaning of those arbitrary numbers. That is a real a-hole thing to do.
Last edited on
these errors usually tell you which symbol is unresolved. Is it "check"? How would Function.cpp know about the definition of "check" (which is in a different file check.cpp) ?

Make a Function.h, Function.cpp, Check.h, Check.cpp files, so that Function.cpp can include Check.h. If all these files are in same project, should compile. (Through naming, Function.cpp should be able to find the correct function definition by looking in Check.cpp file)

Some notes:
- if you're going to shorten files, at least make them syntactically correct. Your initial file example,
maindriver.cpp
1
2
// include structs.h
call function.cpp
,

is not valid code at all.

- Your next example for Structs.h is at the least missing a semicolon and should also have an include guard (all header files should have include guards).

- All the include lines are commented for some reason

- You never actually posted the definition of "check" function, which might be in check.cpp

- Generally not a good habit to have global functions. Typically you want to tuck them inside classes, or at the least namespaces.
Last edited on
I did not think that it was needed this forum is for BEGINNERS. I dont see the point of being rude. I distinctly put in my description if additional info is needed to tell me because I was not sure. I cut it down because I thought it would be easier for people to read. Not because I wanted to be a "a-hole".
For anyone else, the full error is below.
1>Function.obj : error LNK2019: unresolved external symbol "bool __cdecl check(float,float,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int)" (?check@@YA_NMMV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) referenced in function "void __cdecl Function(char * const,float,float,float,char * const,class std::basic_ostream<char,struct std::char_traits<char> > &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int)" (?Function@@YAXQADMMM0AAV?$basic_ostream@DU?$char_traits@D@std@@@std@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@H@Z)
1>C:\Users\akarbarz\source\repos\Practice!\Debug\Practice!.exe : fatal error LNK1120: 1 unresolved externals
Check.h
1
2
3
4
5
6
#ifndef Check_h
#define Check_h

bool Check(float num1, float num2, string pipeType, int pipesize);

#endif 


Check.cpp
1
2
3
4
5
6
#include "Check.h"

bool Check(float num1, float num2, string pipeType, int pipesize)
{
    // ...
}


Function.h
1
2
3
4
5
6
#ifndef Function_h
#define Function_h

void Function(char name[32], float num1, float num2, float num3, char eol[16], ostream &outputFile, string pipeType, int pipesize);

#endif 


Function.cpp
1
2
3
4
5
6
7
8
#include "Function.h"
#include "Check.h"

void Function(char name[32], float num1, float num2, float num3, char eol[16], ostream &outputFile, string pipeType, int pipesize)
{
    // ...
    Check(...);   // Since we include Check.h, compiler knows to look for definition in Check.cpp
}


main.cpp
1
2
3
4
5
6
7
#include "Function.h"

int main()
{
    Function(...);
    return 0;
}

Thank you icy1. I updated the post I hope its better now. I also found my issue! My function prototype in structs.h
 
bool check(float num1, float num2, string pipeType, int pipesize); 


did not match my function "definition"? in check.cpp
 
bool check(float num1,float num2, int pipesize, string pipeType)


Such a silly mistake. Thank you for your help. I will look into including a guard. Thanks again.
Topic archived. No new replies allowed.