[odb-users] undefined reference to `person::person'

Myoungkyu Song mksong at vt.edu
Thu Nov 18 14:26:21 EST 2010


Hello, ODB developers & users

 

gcc -c driver.cxx person-odb.cxx \

-I/home/grads/mksong/odb/libodb/include \

-I/home/grads/mksong/odb/libodb-mysql-1.0.0 \

-I/home/grads/mksong/mysql/include/mysql

 

Fortunately, I have gotten 'driver.o' and 'person-odb.o'. And then, I typed
the following command;

 

gcc -o driver driver.o person-odb.o -lodb -lodb-mysql \

-L/home/grads/mksong/odb/libodb/lib \

-L/home/grads/mksong/odb/libodb-mysql-1.0.0/odb/mysql/.libs

 

However, I have gotten the errors like;

 

[mksong at ap2 bin]$ gcc -o driver driver.o person-odb.o -lodb -lodb-mysql
-L/home/grads/mksong/odb/libodb/lib
-L/home/grads/mksong/odb/libodb-mysql-1.0.0/odb/mysql/.libs

driver.o: In function `main':

driver.cxx:(.text+0x25d): undefined reference to
`person::person(std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&, unsigned short)'

driver.cxx:(.text+0x3b3): undefined reference to
`person::person(std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&, unsigned short)'

driver.cxx:(.text+0x50c): undefined reference to
`person::person(std::basic_string<char, std::char_traits<char>,
std::allocator<char> > const&, std::basic_string<char,
std::char_traits<char>, std::allocator<char> > const&, unsigned short)'

driver.cxx:(.text+0x69e): undefined reference to `person::id()'

driver.cxx:(.text+0x6ac): undefined reference to `person::id()'

driver.cxx:(.text+0x6bd): undefined reference to `person::id()'

collect2: ld returned 1 exit status

[mksong at ap2 bin]$ 

[mksong at ap2 bin]$

 

Attached are my codes I compiled. Would you able to help me out?

 

Best regards,

Myoungkyu Song

 

-------

Myoungkyu Song, PhD Student

Software Innovations Lab, 

Dept. of Computer Science, 

Virginia Tech

2202 Kraft Drive

Blacksburg, VA 24060 

 <mailto:mksong at cs.vt.edu> mksong at cs.vt.edu

 <http://people.cs.vt.edu/~mksong/> http://people.cs.vt.edu/~mksong/

 

-------------- next part --------------
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//

// Begin prologue.
//
//
// End prologue.

#include <odb/pre.hxx>

#include "person-odb.hxx"

#include <odb/mysql/mysql.hxx>
#include <odb/mysql/traits.hxx>
#include <odb/mysql/database.hxx>
#include <odb/mysql/transaction.hxx>
#include <odb/mysql/connection.hxx>
#include <odb/mysql/statement.hxx>
#include <odb/mysql/exceptions.hxx>
#include <odb/mysql/result.hxx>

#include <odb/details/shared-ptr.hxx>

namespace odb
{
  // person
  //

  const mysql::query_column<
    mysql::value_traits< long unsigned int, unsigned long long, mysql::id_ulonglong >::query_type,
    mysql::id_ulonglong>
  access::object_traits< ::person >::query_type::id (
    "`person`.`id`");

  const mysql::query_column<
    mysql::value_traits< ::std::string, details::buffer, mysql::id_string >::query_type,
    mysql::id_string>
  access::object_traits< ::person >::query_type::first (
    "`person`.`first`");

  const mysql::query_column<
    mysql::value_traits< ::std::string, details::buffer, mysql::id_string >::query_type,
    mysql::id_string>
  access::object_traits< ::person >::query_type::last (
    "`person`.`last`");

  const mysql::query_column<
    mysql::value_traits< short unsigned int, unsigned short, mysql::id_ushort >::query_type,
    mysql::id_ushort>
  access::object_traits< ::person >::query_type::age (
    "`person`.`age`");

  const char* const access::object_traits< ::person >::persist_statement =
  "INSERT INTO `person` ("
  "`id`,"
  "`first`,"
  "`last`,"
  "`age`"
  ") VALUES (?,?,?,?)";

  const char* const access::object_traits< ::person >::find_statement =
  "SELECT "
  "`id`,"
  "`first`,"
  "`last`,"
  "`age`"
  " FROM `person` WHERE `id` = ?";

  const char* const access::object_traits< ::person >::update_statement =
  "UPDATE `person` SET "
  "`id` = ?,"
  "`first` = ?,"
  "`last` = ?,"
  "`age` = ?"
  " WHERE `id` = ?";

  const char* const access::object_traits< ::person >::erase_statement =
  "DELETE FROM `person`"
  " WHERE `id` = ?";

  const char* const access::object_traits< ::person >::query_clause =
  "SELECT "
  "`id`,"
  "`first`,"
  "`last`,"
  "`age`"
  " FROM `person` ";

  bool access::object_traits< ::person >::
  grow (image_type& i, my_bool* e)
  {
    bool r (false);

    // id_
    //
    e[0UL] = 0;

    // first_
    //
    if (e[1UL])
    {
      i.first_value.capacity (i.first_size);
      r = true;
    }

    // last_
    //
    if (e[2UL])
    {
      i.last_value.capacity (i.last_size);
      r = true;
    }

    // age_
    //
    e[3UL] = 0;

    return r;
  }

  void access::object_traits< ::person >::
  bind (mysql::binding& b, image_type& i)
  {
    // id_
    //
    b.bind[0UL].buffer_type = MYSQL_TYPE_LONGLONG;
    b.bind[0UL].is_unsigned = 1;
    b.bind[0UL].buffer = &i.id_value;
    b.bind[0UL].is_null = &i.id_null;

    // first_
    //
    b.bind[1UL].buffer_type = MYSQL_TYPE_STRING;
    b.bind[1UL].buffer = i.first_value.data ();
    b.bind[1UL].buffer_length = static_cast<unsigned long> (
      i.first_value.capacity ());
    b.bind[1UL].length = &i.first_size;
    b.bind[1UL].is_null = &i.first_null;

    // last_
    //
    b.bind[2UL].buffer_type = MYSQL_TYPE_STRING;
    b.bind[2UL].buffer = i.last_value.data ();
    b.bind[2UL].buffer_length = static_cast<unsigned long> (
      i.last_value.capacity ());
    b.bind[2UL].length = &i.last_size;
    b.bind[2UL].is_null = &i.last_null;

    // age_
    //
    b.bind[3UL].buffer_type = MYSQL_TYPE_SHORT;
    b.bind[3UL].is_unsigned = 1;
    b.bind[3UL].buffer = &i.age_value;
    b.bind[3UL].is_null = &i.age_null;

    b.version++;
  }

  void access::object_traits< ::person >::
  bind (mysql::binding& b, id_image_type& i)
  {
    b.bind[0UL].buffer_type = MYSQL_TYPE_LONGLONG;
    b.bind[0UL].is_unsigned = 1;
    b.bind[0UL].buffer = &i.id_value;
    b.bind[0UL].is_null = &i.id_null;

    b.version++;
  }

  bool access::object_traits< ::person >::
  init (image_type& i, const object_type& o)
  {
    bool grew (false);
    bool is_null;

    // id_
    //
    mysql::value_traits< long unsigned int, unsigned long long, mysql::id_ulonglong >::set_image (
      i.id_value, is_null, o.id_);
    i.id_null = is_null;

    // first_
    //
    {
      std::size_t size;
      std::size_t cap (i.first_value.capacity ());
      mysql::value_traits< ::std::string, details::buffer, mysql::id_string >::set_image (
        i.first_value,
        size,
        is_null,
        o.first_);
      i.first_size = static_cast<unsigned long> (size);
      i.first_null = is_null;
      grew = grew || (cap != i.first_value.capacity ());
    }

    // last_
    //
    {
      std::size_t size;
      std::size_t cap (i.last_value.capacity ());
      mysql::value_traits< ::std::string, details::buffer, mysql::id_string >::set_image (
        i.last_value,
        size,
        is_null,
        o.last_);
      i.last_size = static_cast<unsigned long> (size);
      i.last_null = is_null;
      grew = grew || (cap != i.last_value.capacity ());
    }

    // age_
    //
    mysql::value_traits< short unsigned int, unsigned short, mysql::id_ushort >::set_image (
      i.age_value, is_null, o.age_);
    i.age_null = is_null;

    return grew;
  }

  void access::object_traits< ::person >::
  init (object_type& o, const image_type& i)
  {
    // id_
    //
    mysql::value_traits< long unsigned int, unsigned long long, mysql::id_ulonglong >::set_value (
      o.id_, i.id_value, i.id_null);

    // first_
    //
    mysql::value_traits< ::std::string, details::buffer, mysql::id_string >::set_value (
      o.first_,
      i.first_value,
      i.first_size,
      i.first_null);

    // last_
    //
    mysql::value_traits< ::std::string, details::buffer, mysql::id_string >::set_value (
      o.last_,
      i.last_value,
      i.last_size,
      i.last_null);

    // age_
    //
    mysql::value_traits< short unsigned int, unsigned short, mysql::id_ushort >::set_value (
      o.age_, i.age_value, i.age_null);
  }

  void access::object_traits< ::person >::
  persist (database&, object_type& obj)
  {
    using namespace mysql;

    connection& conn (mysql::transaction::current ().connection ());
    object_statements<object_type>& sts (
      conn.statement_cache ().find<object_type> ());
    binding& b (sts.image_binding ());

    obj.id_ = 0;

    if (init (sts.image (), obj) || b.version == 0)
      bind (b, sts.image ());

    mysql::persist_statement& st (sts.persist_statement ());
    st.execute ();
    obj.id_ = static_cast<id_type> (st.id ());
  }

  void access::object_traits< ::person >::
  update (database&, const object_type& obj)
  {
    using namespace mysql;

    connection& conn (mysql::transaction::current ().connection ());
    object_statements<object_type>& sts (
      conn.statement_cache ().find<object_type> ());

    bool is_null, grew (false);
    const id_type& id (object_traits::id (obj));
    id_image_type& i (sts.id_image ());
    mysql::value_traits< long unsigned int, unsigned long long, mysql::id_ulonglong >::set_image (
      i.id_value, is_null, id);
    i.id_null = is_null;

    binding& idb (sts.id_image_binding ());
    if (grew || idb.version == 0)
      bind (idb, i);

    binding& imb (sts.image_binding ());
    if (init (sts.image (), obj) || imb.version == 0)
      bind (imb, sts.image ());

    sts.update_statement ().execute ();
  }

  void access::object_traits< ::person >::
  erase (database&, const id_type& id)
  {
    using namespace mysql;

    connection& conn (mysql::transaction::current ().connection ());
    object_statements<object_type>& sts (
      conn.statement_cache ().find<object_type> ());

    bool is_null, grew (false);
    id_image_type& i (sts.id_image ());
    mysql::value_traits< long unsigned int, unsigned long long, mysql::id_ulonglong >::set_image (
      i.id_value, is_null, id);
    i.id_null = is_null;

    binding& idb (sts.id_image_binding ());
    if (grew || idb.version == 0)
      bind (idb, i);

    sts.erase_statement ().execute ();
  }

  access::object_traits< ::person >::pointer_type
  access::object_traits< ::person >::
  find (database&, const id_type& id)
  {
    using namespace mysql;

    connection& conn (mysql::transaction::current ().connection ());
    object_statements<object_type>& sts (
      conn.statement_cache ().find<object_type> ());

    if (find (sts, id))
    {
      pointer_type p (access::object_factory< ::person >::create ());
      pointer_traits< pointer_type >::guard g (p);
      init (pointer_traits< pointer_type >::get_ref (p), sts.image ());
      g.release ();
      return p;
    }

    return pointer_type ();
  }

  bool access::object_traits< ::person >::
  find (database&, const id_type& id, object_type& obj)
  {
    using namespace mysql;

    connection& conn (mysql::transaction::current ().connection ());
    object_statements<object_type>& sts (
      conn.statement_cache ().find<object_type> ());

    if (find (sts, id))
    {
      init (obj, sts.image ());
      return true;
    }

    return false;
  }

  bool access::object_traits< ::person >::
  find (mysql::object_statements<object_type>& sts, const id_type& id)
  {
    using namespace mysql;

    bool is_null, grew (false);
    id_image_type& i (sts.id_image ());
    mysql::value_traits< long unsigned int, unsigned long long, mysql::id_ulonglong >::set_image (
      i.id_value, is_null, id);
    i.id_null = is_null;

    binding& idb (sts.id_image_binding ());
    if (grew || idb.version == 0)
      bind (idb, i);

    binding& imb (sts.image_binding ());
    if (imb.version == 0)
      bind (imb, sts.image ());

    mysql::find_statement& st (sts.find_statement ());
    mysql::find_statement::result r (st.execute ());

    if (r == mysql::find_statement::no_data)
      return false;

    if (r == mysql::find_statement::truncated)
    {
      if (grow (sts.image (), sts.image_error ()))
      {
        bind (imb, sts.image ());
        st.refetch ();
      }
    }

    st.free_result ();
    return true;
  }

  result< access::object_traits< ::person >::object_type >
  access::object_traits< ::person >::
  query (database&, const query_type& q)
  {
    using namespace mysql;

    connection& conn (mysql::transaction::current ().connection ());
    object_statements<object_type>& sts (
      conn.statement_cache ().find<object_type> ());

    binding& imb (sts.image_binding ());
    if (imb.version == 0)
      bind (imb, sts.image ());

    details::shared_ptr<query_statement> st (
      new (details::shared) query_statement (conn,
                                             query_clause + q.clause (),
                                             imb,
                                             q.parameters ()));
    st->execute ();

    details::shared_ptr<odb::result_impl<object_type> > r (
      new (details::shared) mysql::result_impl<object_type> (st, sts));
    return result<object_type> (r);
  }
}

#include <odb/post.hxx>

// Begin epilogue.
//
//
// End epilogue.
-------------- next part --------------
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//

#ifndef PERSON_ODB_HXX
#define PERSON_ODB_HXX

// Begin prologue.
//
//
// End prologue.

#include <odb/version.hxx>

#if (ODB_VERSION != 10000UL)
#error ODB runtime version mismatch
#endif

#include <odb/pre.hxx>

#include "person.hxx"

#include <cstddef>

#include <odb/core.hxx>
#include <odb/traits.hxx>
#include <odb/result.hxx>

#include <odb/mysql/version.hxx>
#include <odb/mysql/forward.hxx>
#include <odb/mysql/mysql-types.hxx>

#include <odb/mysql/query.hxx>

#include <odb/details/buffer.hxx>

namespace odb
{
  // person
  //
  template <>
  class access::object_traits< ::person >: 
    public access::object_memory< ::person >,
    public access::object_factory< ::person >
  {
    public:
    typedef ::person object_type;
    typedef long unsigned int id_type;

    struct image_type
    {
      // id_
      //
      unsigned long long id_value;
      my_bool id_null;

      // first_
      //
      details::buffer first_value;
      unsigned long first_size;
      my_bool first_null;

      // last_
      //
      details::buffer last_value;
      unsigned long last_size;
      my_bool last_null;

      // age_
      //
      unsigned short age_value;
      my_bool age_null;
    };

    struct id_image_type
    {
      unsigned long long id_value;
      my_bool id_null;
    };

    typedef mysql::query query_base_type;

    struct query_type: query_base_type
    {
      // id
      //
      static const mysql::query_column<
        mysql::value_traits< long unsigned int, unsigned long long, mysql::id_ulonglong >::query_type,
        mysql::id_ulonglong>
      id;

      // first
      //
      static const mysql::query_column<
        mysql::value_traits< ::std::string, details::buffer, mysql::id_string >::query_type,
        mysql::id_string>
      first;

      // last
      //
      static const mysql::query_column<
        mysql::value_traits< ::std::string, details::buffer, mysql::id_string >::query_type,
        mysql::id_string>
      last;

      // age
      //
      static const mysql::query_column<
        mysql::value_traits< short unsigned int, unsigned short, mysql::id_ushort >::query_type,
        mysql::id_ushort>
      age;

      query_type ();
      query_type (const std::string&);
      query_type (const query_base_type&);
    };

    static const std::size_t column_count = 4UL;

    static const char* const persist_statement;
    static const char* const find_statement;
    static const char* const update_statement;
    static const char* const erase_statement;
    static const char* const query_clause;

    static id_type
    id (const object_type&);

    static bool
    grow (image_type&, my_bool*);

    static void
    bind (mysql::binding&, image_type&);

    static void
    bind (mysql::binding&, id_image_type&);

    static bool
    init (image_type&, const object_type&);

    static void
    init (object_type&, const image_type&);

    static void
    persist (database&, object_type&);

    static void
    update (database&, const object_type&);

    static void
    erase (database&, const id_type&);

    static pointer_type
    find (database&, const id_type&);

    static bool
    find (database&, const id_type&, object_type&);

    static result<object_type>
    query (database&, const query_type&);

    private:
    static bool
    find (mysql::object_statements<object_type>&, const id_type&);
  };
}

#include "person-odb.ixx"

#include <odb/post.hxx>

// Begin epilogue.
//
//
// End epilogue.

#endif // PERSON_ODB_HXX
-------------- next part --------------
A non-text attachment was scrubbed...
Name: person-odb.ixx
Type: application/octet-stream
Size: 712 bytes
Desc: not available
Url : http://codesynthesis.com/pipermail/odb-users/attachments/20101118/a622728f/person-odb.obj
-------------- next part --------------
// driver.cxx
//

#include <memory>   // std::auto_ptr
#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;

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

    unsigned long john_id, jane_id, joe_id;

    // Create a few persistent person objects.
    //
    {
      person john ("John", "Doe", 33);
      person jane ("Jane", "Doe", 32);
      person joe ("Joe", "Dirt", 30);

      transaction t (db->begin ());

      db->persist (john);
      db->persist (jane);
      db->persist (joe);

      t.commit ();

      // Save object ids for later use.
      //
      john_id = john.id ();
      jane_id = jane.id ();
      joe_id = joe.id ();
    }
  }
  catch (const odb::exception& e)
  {
    cerr << e.what () << endl;
    return 1;
  }
}
 
-------------- next part --------------
#ifndef PERSON_HXX
#define PERSON_HXX
// person.hxx
//

#include <string>
#include <odb/core.hxx>     // (1)

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

  unsigned long id() const;
  const std::string& first () const;
  const std::string& last () const;
  unsigned short age () const;
  void age (unsigned short);

private:
  person () {}              // (3)

  friend class odb::access; // (4)

  #pragma db id auto        // (5)
  unsigned long id_;        // (5)
  std::string first_;
  std::string last_;
  unsigned short age_;
};
#endif
-------------- next part --------------
/* This file was generated by ODB, object-relational mapping (ORM)
 * compiler for C++.
 */

DROP TABLE IF EXISTS `person`;

CREATE TABLE `person` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `first` TEXT NOT NULL,
  `last` TEXT NOT NULL,
  `age` SMALLINT UNSIGNED NOT NULL)
  ENGINE=InnoDB;



More information about the odb-users mailing list