Unresolved externals error - what is that?

My code will compile, but it will not debug.

I receive 2 errors.

Error 2 error LNK1120: 1 unresolved externals

Error 1 error LNK2019: unresolved external symbol "int __cdecl menu(void)" (?menu@@YAHXZ) referenced in function _main

Please help! Does LNK1120 refer to a line number? I have never seen these errors before even though I am a beginner.

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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210

#include <iostream>  
#include <fstream>  
#include <iomanip>  
#include <cctype>  
using namespace std;  
  
const int DESC_SIZE = 15;								
const int DATE_SIZE = 15;							    
struct InventoryItem								    
{  
    char desc[DESC_SIZE];								
    int quantity;										
    double whlCost;											
    double rtlCost;								 
    char date[DATE_SIZE];								
    int menu();
};   
void addRec(fstream &);							
void dispRec(fstream &);							
void chgRec(fstream &);								



 int InventoryItem::menu()

 {  
	 long selection;
	 selection = menu(); 
     int choice;  
     cout << "Please make a selection, 1 through 4." << endl; 
     cout << "1. Add a new record" << endl;  
     cout << "2. View an exisitng record" << endl;  
     cout << "3. Change an exisitng record" << endl;  
     cout << "4. Exit" << endl;  
     cout << endl;  
     cout <<"Enter your choice (1-4): ";  
     cin >> choice;  
     while(choice < 1 || choice > 4)  

     {  
         cout << "Invaild selection!" << endl;  
         cout << "Please enter your choice (1-4) : "<< endl;  
         cin >> choice;
         
	 }
	
     return choice;  

 }  
 
 
 void addRec(fstream &file)											

 {  

     cout << "Enter the following inventory data:"<<endl;  
     fstream inventory("Inventory.txt", ios::out | ios::binary);  
     InventoryItem record;  

    
     cout << "Description: ";  
     cin.ignore();  

     cin.getline(record.desc, 51);  
     cin >> record.desc;  

     cout << "Quantity: ";  
     cin >> record.quantity;  

     cout << "Wholesale cost: ";  
     cin >> record.whlCost;  

     cout << "Retail price: ";  
     cin >> record.rtlCost; 

     cout << "Date added to inventory (in 00/00/0000 format): ";  
     cin >> record.date;  

	 inventory.write(reinterpret_cast<char *>(&record),sizeof(record));  
     cout << "Record added to file."<<endl;  

     file.close();  

 }  

 void dispRec(fstream &file)  

 {  

     fstream inventory ("Inventory.txt", ios::out | ios::binary);  
     InventoryItem record;  
     long recNum;  
     cout << "Enter the record number of the item to view:";  
     cin >> recNum;  

     inventory.seekg(recNum * sizeof(record), ios::beg);  
     inventory.read(reinterpret_cast<char *>(&record),sizeof(record));  
    
     cout << "Description: " << record.desc << endl;  
     cout << "Quantity: " << record.quantity << endl;  
     cout << "Wholesale cost: " << record.whlCost << endl;  
     cout << "Retail price: " << record.rtlCost << endl;  
     cout << "Date (in 00/00/0000 format): " << record.date << endl;  
    
     if(file.fail())  
     file.clear();  
     file.close();  

 }  

   void chgRec(fstream &file)	

 {  

     fstream inventory ("InventoryFile.txt", ios::out | ios::binary);  
     InventoryItem record;   
     long recNum;  
     cout << "Enter the record number of the item you want to edit: ";  
     cin >> recNum;											

     inventory.seekg(recNum * sizeof(record), ios::beg);  
     inventory.read(reinterpret_cast<char *>(&record),sizeof(record));  

     cout << "Description: " << record.desc << endl;  
     cout << "Quantity: " << record.quantity << endl;  
     cout << "Wholesale cost: " << record.whlCost << endl;  
     cout << "Retail price: " << record.rtlCost << endl;  
     cout << "Date (in 00/00/0000 format): " << record.date << endl;    

    

     inventory.seekp(recNum * sizeof(record), ios::beg);  

   

     inventory.write(reinterpret_cast<char *>(&record),sizeof(record));  

	

     inventory.close();   
}
   int main()  
{ 
    long selection;										 
	int menu();
	selection = menu(); 
    fstream inventory ("Inventory.txt", ios::in | ios::out | ios::binary);  
    InventoryItem record = {" ", 0, 0.0};  
      
    cout << fixed << showpoint << setprecision(2);  
    cout<<"Inventory Managment"<<endl;  

  
    for (int count = 0; count < 5; count++)  

    {  

       inventory.write(reinterpret_cast<char *>(&record),sizeof(record));  

    }  

    inventory.close();  

    inventory.open("Inventory.txt", ios::out | ios::binary);  
	
		 while (selection != 4) 

    {  
       switch(selection)  
        {  

		case 1:													  

            {  
                addRec(inventory);  
                break;  
            }  

        case 2:													   

            {  
			    dispRec(inventory);  
                break;  
            }  

        case 3:													  

            {  
                chgRec(inventory);  
                break;  
            }  

        default:												 

            {  
                cout << "Invalid selection" << endl;  
            }  

            selection = record.menu();  
        }  

    }               
  
    inventory.close();      

    
    return 0;  

 }  
Do you have an executable open already? The error is linking it.

Your error is this:

1
2
	int menu();
	selection = menu(); 

In your main function.



Maybe you meant:

1
2
InventoryItem test;
selection = test.menu();



Basically you never created the InventoryItem object and you are trying to call the fucntions without the object.

it would be like trying to call the open function from fstream without creating a fstream object
Last edited on
YOU ARE THE GREATEST!

Now I can actually test this and see that nothing happens. LOL!

I guess it cannot read anything in my text file?????

Hmmmmm....

It gives me the error "Inventory Program.exe has stopped working". My console is blank with "Press any key....

It might have to do with this line:

fstream inventory ("Inventory.txt", ios::in | ios::out | ios::binary);

Looks like you just put all the flags you could think of.

You probably want fstream inventory("Inventory.txt" , ios::in); or maybe ios::nocreate also

I'm not sure what you trying to do with that inventory txt read or write?
Last edited on
Line 148 I thought changes the individual record in the file and that I needed the in, out, and binary.

I need to read a file and be able to change it as necessary.
Last edited on
Remove lines 28 and 29 from your InventoryItem::menu function.

What would you expect the following to do?

1
2
3
4
5
6
void menu() { menu(); }

int main()
{
    menu() ;
}
THANKS!!
Topic archived. No new replies allowed.