0

ODB に付属する「Hello World」の例をコンパイルしようとしています。Debian Linux を使用しています。

person.hxx および driver.cxx ファイルをコピーしました

// person.hxx
#ifndef person_hxx
#define person_hxx

#include <string>
#include <odb/core.hxx>

#pragma db object
class person
{
public:
  person (const std::string& first,
          const std::string& last,
          unsigned short age);

  const std::string& first () const;
  const std::string& last () const;

  unsigned short age () const;
  void age (unsigned short);

private:
  person () {}

  friend class odb::access;

  #pragma db id auto
  unsigned long id_;

  std::string first_;
  std::string last_;
  unsigned short age_;
};

#endif


// driver.cxx

#include <memory>
#include <iostream>

#include <odb/database.hxx>
#include <odb/transaction.hxx>

#include <odb/mysql/database.hxx>

#include "person.hxx"
#include "person-odb.hxx"

using namespace std;
using namespace odb::core;

int main (int argc, char * argv[])
{
  try
    {
      auto_ptr<database> db (new odb::mysql::database (argc, argv));

      unsigned long john_id,jane_id, joe_id;
      {
        person john("John","Doe", 33);
    person jane ("Jane","Doe", 32);
        person joe("Joe","Dirt",30);

    transaction t (db -> begin());

        john_id = db->persist(john);
        jane_id = db->persist(jane);
        joe_id = db->persist(joe);

        t.commit();
      }
    }
  catch (const odb::exception& e)
    {
      cerr << e.what() <<endl;
      return 1;
    }
}

drivertheodb コンパイラは正常に動作し、person-odb ファイルを生成しました。

私はそれらをコンパイルしました

g++ -c deiver.cxx
g++ -c person-odb.cxx

そしてすべてうまくいった。

問題はリンクフェーズから始まりました

g++  driver.o  person-odb.o -lodb-mysql -lodb -o driver

その結果、

driver.cxx:(.text+0x14d): undefined reference to `person::person(std::string const&, std::string const&, unsigned short)'
4

2 に答える 2