Error while testing.

Hello. I have the following files& code

Main.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
#include "move.h"
#include <ncurses.h>

int main()
{
        moveClass moveObj;
        moveObj.startProgram();

        initscr();
        noecho();
        raw();


        bool isRunning = true;

        while(isRunning = true)
        {

        }
printw("yo");
        endwin();
}

~           

(note, program is not finished yet, just doing a test that doesn't seem to be working, which is why I hvae a empty while loop)

move.cpp
1
2
3
4
5
6
7
8
9
10
#include "move.h"
#include <ncurses.h>

void moveClass::startProgram()
{
        curX = 0;
        curY = 4;
}



move.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#ifndef MOVE_H
#define MOVE_H

        class moveClass {
                private:
                int cursX;
                int cursY;
                char moveChar;
                public:
                void startProgram();
        };
#endif
~                                                                       
~                                


I get the following error:
undefined reference to `moveClass::startProgram()'
collect2: ld returned 1 exit status
Please explain to me what the problem is, and then how to fix it.
It's a linker error.

If you are using an IDE, make sure that move.cpp is added to the project.

If you are compiling from the command line, make sure that move.cpp is compiled and linked properly.
Exactly how this is done depends on the compiler. In GCC you can do
1
2
3
g++ -c Main.cpp
g++ -c move.cpp
g++ -o nameOfExecutable Main.o move.o -lncurses

Or you can do compiling and linking in one line
g++ -o nameOfExecutable Main.cpp move.cpp -lncurses
Topic archived. No new replies allowed.