I'm having some garbage output error messages and I don't understand what they mean

Lily Hartle 1 Reputation point
2021-03-05T04:28:25.903+00:00

I'm getting this error message and I have no idea what it means.

1>gamedriver.obj : error LNK2019: unresolved external symbol "int __cdecl random(class Board)" (?random@@YAHVBoard@@@Z) referenced in function _main
1> Hint on symbols that are defined and could potentially match:
1> "int __cdecl random(class Board (* const)[7])" (?random@@YAHQAY06VBoard@@@Z)
1>C:\Users\hlili\source\repos\Project2\Debug\Project2.exe : fatal error LNK1120: 1 unresolved externals

Please help or direct me to someone who can help. Thank You.

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
2,904 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Guido Franzke 2,196 Reputation points
    2021-03-05T07:04:49.967+00:00

    Hello,
    the error means that the linker cannot find the function definition of int random(class Board).
    This is not a Standard function. You implemented the function by yourself, or you use the function that is provided in a library or dll.
    Since the compiler finds the declaration (so you have the correct include file), you can right click on the function and go to the declaration. VS will jump into the include file. If you right-click the function and go to the definition, VS will try to show the source code of the definition. I think it is hidden in a library or dll, so you can only see the declaration. If you see the source code of the function and it is in a cpp file, then you must add the cpp file to your project. If the function is hidden in a dll, then you will only see source code for calling the function in the dll.
    In your project properties you must add the library (.lib file) to the linker input dependencies. Normally there is a lib file for a dll too, that you must add to the linker input in your project.
    Regards, Guido


  2. Guido Franzke 2,196 Reputation points
    2021-03-08T08:41:38.61+00:00

    So, you say:
    In the main: move = random(playboard); //playboard is a Board object
    After the main: int random(Board board[6][7]) //the Board object is an array of other objects

    You have not defined a function for int random(Board). You only define a function int random(Board b[6][7]).
    These are not the same. The first will take one Board variable. The second will take a two-dimensional array.
    If you use random(playboard), you don't call the two-dimensional function, but you call the first function. You have not defined this function! That's why the linker complains. You must implement the function int random(Board).

    Regards, Guido

    0 comments No comments

  3. Sam of Simple Samples 5,471 Reputation points
    2021-03-05T18:44:46.817+00:00

    Those messages are normal messages for the C++ compiler, not garbage. The following are called decorations that use something that is sometimes called name mangling.

    • ?random@@YAHVBoard@@@Z
    • ?random@@YAHQAY06VBoard@@@Z

    Those are the compiler's way to refer to method signatures as in Type signature - Wikipedia. You can undecorate them using the undname.exe tool, as in Decorated Names. The following are the result of the tool using each of the previous.

    • int __cdecl random(class Board)
    • int __cdecl random(class Board (* const)[7])

    That corresponds to the error messages. The message says that you are trying to call the random method with a single instance of the Board class but that signature does not exist. There is a random method with a different signature. If you are still unsure of how to solve the problem then provide more information here, as @Viorel requests.

    Update: based on the code provided it is still not clear what you need to do but I hope the following helps. You are using C-language two-dimensional arrays. They are difficult to use. So the C++ language provides the vector class.. You can find relevant tutorials and books. The following is hopefully a sample of how to do what you are trying to do.

    #include <iostream>  
    #include <vector>  
    
    class Board  
    {  
    public:  
     int something;  
    };  
    
    int random(std::vector<std::vector<Board>>);  
    
    int main()  
    {  
     std::cout << "Begin play.\n";  
     std::vector<std::vector<Board>> playboard(6, std::vector<Board>(7));  
     std::vector<std::vector<Board>>::iterator row;  
     std::vector<Board>::iterator col;  
     int i = 0;  
     for (row = playboard.begin(); row != playboard.end(); row++) {  
     for (col = row->begin(); col != row->end(); col++) {  
     col->something = ++i;  
     }  
     }  
     random(playboard);  
    }  
    
    int random(std::vector<std::vector<Board>> playboard)  
    {  
     std::vector<std::vector<Board>>::iterator row;  
     std::vector<Board>::iterator col;  
     std::cout << "This is random.\n";  
     for (row = playboard.begin(); row != playboard.end(); row++) {  
     for (col = row->begin(); col != row->end(); col++) {  
     std::cout << col->something << ' ';  
     }  
     std::cout << std::endl;  
     }  
     return 0;  
    }  
    

    The following also works.

    class Board  
    {  
    public:  
        int something;  
    };  
    
    int random(Board);  
    
    int random(Board board[6][7]); //the Board object is an array of other objects  
    
    int main()  
    {  
        Board playboard[6][7];  
        random(playboard); //playboard is a Board object  
        return 0;  
    }  
    int random(Board board[6][7]) { //the Board object is an array of other objects  
        std::cout << "This is random.\n";  
        return 0;  
    }  
    

  4. Lily Hartle 1 Reputation point
    2021-03-07T18:05:20.943+00:00

    and the function looks like:
    int random(Board board[6][7])
    {
    int column;

    column = rand() % 7 + 1;
    while (board[0][column].toString() != "X")      //pull information from arr
    {
        column = rand() % 7 + 1;
    }
    return column;
    

    }

    0 comments No comments