0

I have tried to simplify my situation as much as possible. I have two separate classes in two folders.

/RedRocket/model/dbhandler.h and
/RedRocket/textui/screen.h

When I make a connection between these two run a method, Im getting the following errors.

/home/ktdilsiz/projectworking1/trunk/RedRocket/textUI/screen.cpp:25: error: undefined reference to `DBHandler::test()'
:-1: error: collect2: ld returned 1 exit status

I simply want the connection to work so that I could use my methods. Here is the code that I think is relevant.

screen.h

#ifndef SCREEN_H
#define SCREEN_H
#include "../model/dbhandler.h"
#include "ncurses.h"
#include <string>
#include <vector>

//Parent class for any of the text screens.
class Screen
{
public:

void test();
};    
#endif // SCREEN_H

screen.cpp file:

#include "screen.h"

void test(){
    DBHandler *db;
    db->test();
}

Next is dbHandler.h

#ifndef DBHANDLER_H
#define DBHANDLER_H
#include <algorithm>
#include <sqlite3.h>
#include <vector>
#include <cstring>
#include "log.h"

/* Class to handle interaction with the local test database in the /db_tools directory.  Run ./newDB.sh in that directory prior to use. */
class DBHandler {

public:
    void test();
}
#endif // DBHANDLER_H

dbhandler.cpp

#include "dbhandler.h"

void DBHandler::test(){

}

I tried to read about "collect2: ld returned 1 exit status" error but there are multiple different answers and it didnt resolve the situation. Also, if I add:

#include "../model/dbhandler.cpp"

to the screen.h header file, I get multiple definitions error. I can give more information about this case if you think that I should be focused on solving that error.

If I'm missing anything that could be important, please let me know.

edit1:

It was marked as a duplicate and I did read the given link, and I will read it again now but I could not figure out the problem.

Kemal Tezer Dilsiz
  • 3,739
  • 5
  • 24
  • 43
  • I'm just commenting here to highlight the edit I made about this question being a duplicate. I have read the given link but I still require assistance. Could you at least give me some tips about it? – Kemal Tezer Dilsiz Apr 26 '16 at 18:15
  • I solved the problem (not thanks to the link provided) If anyone has this kind of problem, check your other files that may include dbhandler.h or screen.h. We had a third folder /RedRocket/unittest and my unittest main.cpp file would pull in screen.h but dbhandler.h was not specifically included in the unittest.pro file. Therefore, the problem in the unittest file made it not possible to compile textui.pro – Kemal Tezer Dilsiz Apr 26 '16 at 21:46

1 Answers1

0

Not sure if it's a typo, is it dbHandler.h or dbhandler.h?

Nikos Kazazakis
  • 792
  • 5
  • 19