Einzelnen Beitrag anzeigen

geisi

Registriert seit: 19. Sep 2003
449 Beiträge
 
Delphi 6 Professional
 
#1

c++: undefined reference to ...

  Alt 15. Dez 2009, 09:20
hallo, hab jetzt schon lange delphi programmiert und wollte mal ein bisschen c++ programmieren, doch ich schaff es nicht. ich hab jetzt schon ewig im netz gesucht, aber nichts gefunden. ich weiß ja nicht einmal, wo ich den fehler mache: beim compilieren, in der settings.h, ...?

settings.h:
Code:
class Settings
{
  private:
    char* db;
    char* server;
    char* user;
    char* passwd;
  public:
    Settings();
    char* getDB();
};
settings.cpp:
Code:
#include "settings.h"
#include <stdlib.h>
#include <stdio.h>
#include <iostream.h>

using namespace std;

Settings::Settings()
{
  db = "testadmin";
  server = "localhost";
  user = "xxx";
  passwd = "xxx";
}

char* Settings::getDB()
{
  return db;
}
first_test.cpp:
Code:
#include <iostream>
#include <mysql++.h>
#include <stdlib.h>
#include "settings.h"

using namespace std;

int main(int argc, char* argv[])
{
  Settings::Settings s;
  mysqlpp::Connection conn(false);
  if(conn.connect(s.getDB(), "localhost", "xxx", "xxx"))
  {
    mysqlpp::Query query = conn.query("select ...");
    if(mysqlpp::StoreQueryResult res = query.store()) {
      cout << "phone_number of user 1 is " << res[0][0] << "\n";
    }
    else {
      cerr << "Failed to get phonenumber from user 1: " << query.error() << "\n";
      return 1;
    }
    return 0;
  }
  else {
    cerr << "DB connection failed: " << conn.error() << "\n";
    return 1;
  }
}
Makefile:
Code:
CXX := g++
CXXFLAGS := -I/usr/include/mysql -I/usr/include/mysql++
LDFLAGS := -L/usr/lib -lmysqlpp -lnsl -lz -lm
EXECUTABLE := main

 all: first_test

  clean:
        rm -f $(EXECUTABLE) *.o
Beim compilieren bekommen ich immer einen undefined reference to fehler:
Code:
# make
g++ -I/usr/include/mysql -I/usr/include/mysql++  -L/usr/lib -lmysqlpp -lnsl -lz -lm first_test.cpp  -o first_test
/tmp/ccZp8kS2.o: In function `main':
first_test.cpp:(.text+0xa3): undefined reference to `Settings::Settings()'
first_test.cpp:(.text+0xc1): undefined reference to `Settings::getDB()'
collect2: ld gab 1 als Ende-Status zurück
make: *** [first_test] Fehler 1
mfg geisi
  Mit Zitat antworten Zitat