[odb-users] simple test program does not compile

roberto minarelli roberto.minarelli.de at gmail.com
Mon Jun 12 07:41:40 EDT 2023


Hello odb-users
I report the following situation:

I got this simple class

#include <odb/core.hxx>

#pragma db object table("myschema.myTable")
class myClass
{
public:
    myClass() {}

    virtual ~myClass() {}

    void setIdT(unsigned long value)       {ulId=value;}
    void setGroup(unsigned short value)     {usGroup=value;}
    void setDate(std::string& value)      {strDate=value;}

    unsigned long getId() const       {return ulId;}
    unsigned short getGroup() const     {return usGroup;}
    std::string getUpdateDate() const       {return strUpdateDate;}

private:
    friend class odb::access;

#pragma db id column("idtable") type("number")
    unsigned long ulId;
#pragma db column("group") type("number")
    unsigned short usGroup;
#pragma db column("updateDate") type("date")
    std::string strDate;
};

I generated the odb classes and wrote the following simple test program

#include <iostream>
#include <string>

#include <odb/database.hxx>
#include <odb/transaction.hxx>
#include <odb/oracle/database.hxx>
#include <odb/oracle/connection-factory.hxx>

#include "myClass-odb.hxx"

using namespace std;
using namespace odb;

unique_ptr<oracle::connection_factory>
getConnection(unique_ptr<oracle::connection_factory>& f)
{
    unique_ptr<oracle::connection_factory> res=move(f);
    return res;
}

int main(void)
{
    myClass object;

    string strDate("20230516120506");
    string strUser("tiger");
    string strPwd("scott");
    string strDBname("db");
    try
    {
        unique_ptr<oracle::connection_factory> f (new
oracle::connection_pool_factory (1, 20));

        shared_ptr<oracle::database> db (new oracle::database (strUser,
strPwd, strDBname,0, 0, 0, getConnection(f) ));

        transaction t(db->begin());
        object.setId(200);
        object.setGroup(0);
        object.seteDate(strDate);
        db->persist(object);
t.commit();

    }
    catch(std::exception& e)
    {
        std::cout<<e.what()<<std::endl;
    }
    return 0;

}

and then I gave the following command
g++ -std=c++1z test.cpp -I -lodb -lodb-oracle
that always terminates with the following error
/tmp/ccL4p8cm.o: In function `odb::object_traits<myClass>::id_type
odb::database::persist_<myClass, (odb::database_id)3>(myClass&)':
test.cpp:(.text._ZN3odb8database8persist_I20myClassLNS_11database_idE3EEENS_13object_traitsIT_E7id_typeERS5_[_ZN3odb8database8persist_I20myClassLNS_11database_idE3EEENS_13object_traitsIT_E7id_typeERS5_]+0x1f):
undefined reference to `odb::access::object_traits_impl<myClass,
(odb::database_id)3>::persist(odb::database&, myClass const&)'
collect2: error: ld returned 1 exit status

where is the error?
Or if there is no error why it does not compile?

I am currently using gcc 8 on OL8.7 and odb 2.5.0-b.23

Thanks a lot

Best Regards

Roberto Minarelli Della Valle


More information about the odb-users mailing list