[odb-users] Use of persistent class with virtual member in another module (linker error)

Сергей Никонов shprotello at mail.ru
Fri Feb 15 15:42:47 EST 2019


Hi, all

I've received a linker error in the following situation:

Module A

struct data
{
  double x;
  double y;
};

#pragma db value( data ) definition
#pragma db member( data ::x) access(x)
#pragma db member( data ::y) access(y)

#pragma db object
class person
{
public:
  person() {}

private:
  friend class odb::access;

#pragma db id auto
  int m_id;
#pragma db transient
  data m_d;
#pragma db member(d) virtual(data) access(m_d)
};

Module B

#pragma db object
class dummy
{
public:
  dummy() {}

private:
#pragma db id auto
  int m_id;
#pragma db not_null
  std::shared_ptr<person> m_p;
};

This is a bit sanitized example, but it describes the situation in general.

I use odb-2.5.0-b.3 version under VS2015. Modules are compiled with dynamic multi-database support. Module A exports both common and DB specific code. Module B is linked with common and DB specific Module A libraries. When I build Module B I receive a linker error like the following:

error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl odb::query_columns<class ::person,2,struct odb::alias_traits<class ::person,2,struct odb::access::object_traits<class ::dummy>::p_tag> >::p_class_::p_class_(void)"... referenced in function "void __cdecl `dynamic initializer for 'public: static struct odb::query_columns<class ::person,2,struct odb::alias_traits<class ::person,2,struct odb::access::object_traits<class ::dummy>::p_tag> >::p_class_ const odb::query_columns<class ::person,2,struct odb::alias_traits<class ::person,2,struct odb::access::object_traits<class ::dummy>::p_tag> >::p''(void)" …

But, when I exclude the virtual field from class "person" and use an ordinary m_d field instead, Module B is built successfully.

The questions are:
- Is it possible to use virtual members in the described context?
- and if so, what I did wrong?

Sergey


More information about the odb-users mailing list