Linker Errors

I am using Dev C++ and I get linker errors for playgame, loadgame and playmultiplayer, I am copying the code from a tutors hand out, I have checked and triple checked and I have copied it correctly. Thank you in advance for any help.

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
  #include <iostream>

using namespace std;

void playgame();
void loadgame();
void playmultiplayer();

int main()
{
    int input;
    
    cout << "1. Play game\n";
    cout << "2. Load game\n";
    cout << "3. Play multiplayer\n";
    cout << "4. Exit\n";
    cout << "Selection: ";
    cin >> input;
    switch ( input ) {
           case 1: // Note the colon, not a semicolon
           playgame();
           break;
           case 2: // Note the colon, not a semicolon
           loadgame();
           break;
           case 3: // Note the colon, not a semicolon
           playmultiplayer();
           break;
           case 4: // note the colon, not a semicolon
           cout << "Thank you for playing!\n";
           break;
           default: "Error, bad input, quitting\n";
           break;
           }
           cin.get();
           return 0;
           }
What does the linker complain about?

In the code that you show, you do declare on line 5 that there is a function with name "playgame". Without that declaration the compiler could not compile the function "main", specifically the line 21. Good so far.

The linker on the other hand has to hook up the compiled implementation of the "playgame" so that the binary can actually execute the function when the main function calls it. The error is thus probably that the linker cannot find from any of the object files or libraries implementation for the void playgame().

You need to have a
1
2
3
4
void playgame()
{
  // something
}

It does not need to be in the same source file as main, but it has to be compiled and included for linking.
The errors are as follows:

[Linker error] undefined reference to `playgame()'
[Linker error] undefined reference to `loadgame()'
[Linker error] undefined reference to `playmultiplayer()'
ld returned 1 exit status
C:\Dev-Cpp\Switch Case\Makefile.win [Build Error] ["Switch] Error 1

Sorry, I should of included them in the beginning.
Topic archived. No new replies allowed.