0

I know people asked about this several times but the solutions they got don't fix my problem (cause I'm a noob in C++).

I have 3 files. Main.cpp, Sql.cpp, Sql.hpp. I included in my main the Sql.hpp. When I call a method getDate() from the main it works fine. However, when I call a method select() from the main method I get the error in the title. Here are the two methods and the calls:

select()

void select(const string table, const string column, const string condition, const string condition_2, const string condition_3) {
    otl_stream s;
    const string select = str(format("SELECT %2% FROM %1% WHERE %3% < 20130619 AND %4% = 'someValue' AND (%5% = 'someValue' OR %5% = 'someValue' ")
        % table % column % condition % condition_2 % condition_3);
    cout << select;

getDate()

string Sql::getDate() {
    time_t rawtime;
    struct tm *timeinfo;
    char buffer [80];

    time (&rawtime);
    timeinfo = localtime (&rawtime);

    strftime (buffer, 80,"%Y%m%d", timeinfo);
    string date = buffer;

    return date;
}

Main

Sql sql(host, user, pwd, db, driver);
if(sql.open()) {
    cout << "Datenbankverbindung erfolgreich" << endl;
    sql.getDate();
    sql.select(table, column, condition, condition2, condition3);   
}

The error I get is the following:

g++ "-IC:\\Users\\USERNAME\\Desktop\" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\Main.o" "..\\src\\Main.cpp" 
g++ -o edv-vac-xml.exe "src\\xml.o" "src\\sql.o" "src\\header\\tinyxml2\\tinyxml2.o" "src\\Main.o" -lodbc32 -lcomctl32 
src\Main.o: In function `main':
C:\Users\USERNAME\Desktop\edv-vac-xml\Debug/../src/Main.cpp:39: undefined reference to `Sql::select(std::string, std::string, std::string, std::string, std::string)'

collect2: ld returned 1 exit status 
jerry
  • 2,581
  • 1
  • 21
  • 32
FRules
  • 739
  • 1
  • 10
  • 20
  • Probably one of http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix. – chris Jun 25 '13 at 13:15

1 Answers1

1

If select is supposed to be a routine for the sql class. You should add

void Sql::select(...) {
 ...
}
quinz
  • 1,282
  • 4
  • 21
  • 33