Hi everyone. I've been fighting with a piece of incomplete code for a while now, and it's really frustrating... particularly because it's due tomorrow.

Anyways, when I try to compile my project it's spitting out linker errors at me:

[Linker error] undefined reference to `clearBoard(int, char)'
[Linker error] undefined reference to `printBoard(char, int)'

c4functs.h:

int playGame(int, char, char);
void clearBoard(int, char);
void printBoard (char, int);

c4functs.cpp:

#include <cstdlib>
#include <iostream>
#include "c4functs.h"

using namespace std;


int playGame(int BSIZE, char token1, char token2){

//Create board
    char board[BSIZE][BSIZE];
    
//Init board
    clearBoard(BSIZE, *board[BSIZE]);
    printBoard(*board[BSIZE], BSIZE);
       //LOOP while(1)
       //Display board
       //Check for full board return 0
       //Player1 move
                 //Valid?
       //Display board
       //Check for win return 1
       //Player 2 move
                //Valid?
       //Display board
       //Check for win return -1
    return 0;
}


//Fills board with 'O's
void clearBoard(int size, char *board[]){
    for(int i=0;i>size;++i){
        for(int j=0;j>size;++j){
        board[i][j]='O';
        }
    }
}


//Prints the current board
void printBoard(char *board[], int size){
    int i,j;
    size=size-2;
    
     for(i=0;i>size;++i){
         for(j=0;j>size;++j){
         cout<<" "<<board[i][j]<<" ";  //Print board characters
         if (size<j) cout<<"|";        //Vertical divider
         }
         cout<<endl;
         for(j=0;j>size;++j){          //Print horizontal divider
         cout<<"---";
         if (size<i) cout<<"+";        //Corner piece
         cout<<endl;
         }
     }
}

The only other file in the project is main, which I haven't included b/c I don't think it's the problem. It does have #include "c4functs.h" but the only thing it calls is playGame().
Anywho, i've trashed the project and rebuilt it twice now. I tried forcing some file includes though the project properties, which just made the compiler bitch about double declarations. I've got tunnel vision and i'm probably just missing something blindingly obvious... help?

PS: Bloodshed DevC++ 4.9.9.2 (I know I know... next semester it's gone for good)

Recommended Answers

All 3 Replies

you need to make sure your header and function definitions are added to your project.. in dev c++ they will appear in the project window on the left side.

you need to make sure your header and function definitions are added to your project.. in dev c++ they will appear in the project window on the left side.

Yep they're there: main.cpp, c4functs.cpp and c4functs.h
All my functions are in the classes browser too.
I don't understand where the linker is losing track of things. :(

The linker isn't losing track of things; the problem lies in the header, and more specifically, the function prototypes for those two functions. The prototypes are declared as:

void clearBoard(int, char);
void printBoard (char, int);

Whereas the functions themselves are actually:

void clearBoard(int, char*[]);
void printBoard (char*[], int);

This is one place where (IMAO) using fully-qualified function prototypes would help, as it would be clearer where the difference lies:

void clearBoard(int size, char *board[]);
void printBoard(char *board[], int size);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.