我必须在我的项目中使用ODB 框架。我有 2 个文件:station.hxx
并common.hxx
包含以下内容:
common.hxx
#ifndef COMMON_HXX
#define COMMON_HXX
#include <string>
#pragma db value
struct ProcessAggregateName
{
#pragma db column("SHORTNAME")
std::string SHORTNAME;
#pragma db column("LONGNAME")
std::string LONGNAME;
#pragma db column("SECONDARYNAME")
std::string SECONDARYNAME;
};
#pragma db value
struct Reporting
{
#pragma db column("OPERATIONALLOG")
std::string OPERATIONALLOG;
#pragma db column("PRINTER")
std::string PRINTER;
#pragma db column("HIGHLIGHTING")
bool HIGHLIGHTING;
#pragma db column("REPORTTYPE")
std::string REPORTTYPE;
};
#endif // COMMON_HXX
车站.hxx
#ifndef STATION_HXX
#define STATION_HXX
#include <string>
#include "common.hxx"
#pragma db object table("STATION")
class station
{
public:
station () {}
#pragma db id column("ID")
int ID;
#pragma db column("OPERATINGDOMAIN")
long OPERATINGDOMAIN;
#pragma db column("NAME")
ProcessAggregateName NAME;
#pragma db column("EXPORTBASICDATA")
bool EXPORTBASICDATA;
#pragma db column("EXPORTPROCESSDATA")
bool EXPORTPROCESSDATA;
#pragma db column("IMPORTBASICDATA")
bool IMPORTBASICDATA;
#pragma db column("IMPORTPROCESSDATA")
bool IMPORTPROCESSDATA;
#pragma db column("REPORTING")
Reporting REPORTING;
};
#endif // STATION_HXX
这样做的原因:我想使用common.hxx
在其他文件中声明的结构,所以我想将它们集中在同一个头文件中,并在我需要的任何地方包含它。我的问题:如果我这样做,我会收到如下链接器错误:
错误 LNK2019:未解析的外部符号“公共:静态 void __cdecl odb::access::composite_value_traits::bind(struct odb::mssql::bind *,struct odb::access::composite_value_traits::image_type &,enum odb:: mssql::statement_kind)" (?bind@?$composite_value_traits@UProcessAggregateName@@$03@access@odb@@SAXPAU0mssql@3@AAUimage_type@123@W4statement_kind@43@@Z) 在函数“public: static void __cdecl odb: :access::object_traits_impl::bind(struct odb::mssql::bind *,struct odb::access::object_traits_impl::image_type &,枚举 odb::mssql::statement_kind)" (?bind@?$object_traits_impl@ Vstation@@$03@access@odb@@SAXPAU0mssql@3@AAUimage_type@123@W4statement_kind@43@@Z)
错误 LNK2019:未解析的外部符号“公共:静态 void __cdecl odb::access::composite_value_traits::init(struct odb::access::composite_value_traits::image_type &,struct ProcessAggregateName const &,enum odb::mssql::statement_kind) " (?init@?$composite_value_traits@UProcessAggregateName@@$03@access@odb@@SAXAAUimage_type@123@ABUProcessAggregateName@@W4statement_kind@mssql@3@@Z) 在函数中引用 "public: static void __cdecl odb::access:: object_traits_impl::init(struct odb::access::object_traits_impl::image_type &,class station const &,enum odb::mssql::statement_kind)" (?init@?$object_traits_impl@Vstation@@$03@access@odb@ @SAXAAUimage_type@123@ABVstation@@W4statement_kind@mssql@3@@Z)
如果我直接复制 and 的声明ProcessAggregateName
而不是 include ,一切都会好起来的。我做错了什么,如何在单个标头中声明常用结构并将其包含在多个 *.hxx 文件中?Reporting
station.hxx
common.hxx