- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试按照本教程学习如何使用 C++ 和 ODB:
http://www.codesynthesis.com/products/odb/doc/manual.xhtml#2
我创建了一个 Person.hxx 文件,其中将类 Person 声明为持久的,然后我有三个文件 Person-odb:.cxx、.hxx、.ixx
现在我应该编译 Person-odb.cxx
g++ -I/usr/lib/odb/i686-linux-gnu/include Person-odb.cxx
但结尾是:
fatal error: odb/pgsql/version.hxx: No such file or directory. compilation terminated.
我看到有一个文件 version.hxx 但没有 odb/pgsql 目录...怎么了?
这是 Person.hxx,我在其中定义了持久类 Person:
#ifndef PERSON_HXX
#define PERSON_HXX
#include <string>
#include <odb/core.hxx>
using namespace std;
#pragma db object
class Person {
private:
Person() {
}
friend class odb::access;
#pragma db id auto
unsigned long id_;
std::string email_;
std::string first_;
std::string last_;
unsigned short age_;
public:
Person(const std::string& first, const std::string& last,
unsigned short age);
/* getters */
const std::string& first() const;
const std::string& last() const;
unsigned short age() const;
const std::string& email() const;
/* setters */
void setAge(unsigned short);
void setFirst(const std::string&);
void setLast(const std::string&);
void setEmail(const std::string&);
};
#endif
然后我必须用 odb 编译器编译 Person.hxx:
odb -d mysql --generate-query --generate-schema Person.hxx
我得到 4 个文件 Person.odb.hxx、.cxx、.sql、.ixx这是 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;
int main(int argc, char* argv[]) {
try {
auto_ptr<database> db (new odb::mysql::database (argc, argv));
unsigned long marcoID, loryID, lucaID;
/*Create some persistent Person objects */
Person marco ("Marco", "Di Nicola", 26);
Person luca ("Luca", "La Sala", 22);
Person lory ("Lorenzo", "Vinci", 24);
transaction t (db->begin());
marcoID = db->persist(marco);
lucaID = db->persist(luca);
loryID = db->persist(lory);
t.commit();
} catch (const odb::exception& e) {
cerr << e.what() << endl;
return 1;
}
}
这是文件 Person-odb.hxx
// This file was generated by ODB, object-relational mapping (ORM)
// compiler for C++.
//
#ifndef PERSON_ODB_HXX
#define PERSON_ODB_HXX
#include <odb/version.hxx>
#if (ODB_VERSION != 20200UL)
#error ODB runtime version mismatch
#endif
#include <odb/pre.hxx>
#include "Person.hxx"
#include <memory>
#include <cstddef>
#include <odb/core.hxx>
#include <odb/traits.hxx>
#include <odb/callback.hxx>
#include <odb/wrapper-traits.hxx>
#include <odb/pointer-traits.hxx>
#include <odb/container-traits.hxx>
#include <odb/no-op-cache-traits.hxx>
#include <odb/result.hxx>
#include <odb/simple-object-result.hxx>
#include <odb/details/unused.hxx>
#include <odb/details/shared-ptr.hxx>
namespace odb
{
// Person
template <>
struct class_traits< ::Person >
{
static const class_kind kind = class_object;
};
template <>
class access::object_traits< ::Person >
{
...
#include "Person-odb.ixx"
#include <odb/post.hxx>
#endif // PERSON_ODB_HXX
当我执行时似乎一切正常:
c++ -c Person-odb.cxx
c++ -c driver.cxx
但最后当我必须将所有链接在一起时:
c++ -o driver driver.o Person-odb.o -lodb-mysql -lodb
我得到:
“对 `Person::Person(std::basic_string, std::allocator > const&, std::basic_string, std::allocator > const&, unsigned short)' 的 undefined reference ”
最佳答案
您的问题似乎是您没有安装 ODB。 Installing ODB页面应该让你启动并运行。
您会看到一个 version.hxx 文件,但这是 ODB 编译过程的输入文件,而不是用于包含在您的程序中。
如果您确实安装了它,请找出您系统上的位置并将该文件夹添加到您的编译器包含路径。你的编译命令就变成了
g++ -I/usr/lib/odb/i686-linux-gnu/include -I/path/to/odb/install/include Person-odb.cxx
根据您的编辑,我认为问题是您没有链接到 Person
目标文件,只有 Person-odb 文件。
用
编译Person.cxx
g++ -c Person.cxx
并将您的链接命令更改为
g++ -o driver driver.o Person.o Person-odb.o -lodb-mysql -lodb
应该修复错误。
请注意,我不知道 ODB。我试图从纯 C++ 的角度来解决这个问题。
关于c++ - odb/pgsql/version.hxx 没有那个文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17320867/
我正在使用JQuery Mobile,有两个可用版本:稳定版和旧版。我不熟悉后者。 什么是旧版?或与稳定版有什么区别? 建议在生产现场中使用哪一个? 非常感谢 最佳答案 旧版本是一个旧的稳定版本,由于
Lotus Notes 具有“版本控制”功能。您可以将其设置为在用户需要单击 File->New->Version 以创建新版本的模式下工作。我想在表单上的按钮中使用该功能。 有没有办法(使用 Lot
关闭。这个问题是opinion-based 。目前不接受答案。 已关闭10 年前。 已锁定。这个问题及其答案是locked因为这个问题是题外话,但却具有历史意义。目前不接受新的答案或互动。 是否有任何
我对使用数据库和数据库设计/创建模式非常陌生,我非常感谢一些建议/建议。我正在创建一个应用程序,用户在其中输入数据,并向用户提供该数据的版本控制。用户可以进入并恢复更改或更新值(有点像 git)等,我
尝试启动带头 Selenium session 时出现此错误。 我使用的命令是driver = webdriver.Chrome(executable_path=r'C:\Users\Administ
Apple 的文档本来可以更清楚地说明如何提交更新版本。 正如标题所问,有什么区别 itunes connect 中的版本号(提交更新时必须提供) xcode 中的捆绑版本 捆绑版本字符串,短 它们有
当我在我的 Android 设备上运行我的应用程序时出现错误: meteor run android-device --settings settings.json --mobile-server=m
v = data.getValues(XP_PHONE); for (int i = 0; i alter 'table_foo', {NAME => 'column_fam_foo', V
我在Google CoLab中有这样一个错误:。以下是我的Cuda和Torch版本:。CUDA版本:。这是pytorch版本:2.0.1+cu118我试图安装Cuda 11.8,但没有成功。
我从其他用户那里发现了“类似”的问题,但没有一个答案有效。我正在尝试安装这些软件包: if (!require("BiocManager")) install.packages("BiocMana
我正在使用 Version Maven Plugin插件 use-latest-versions将 groupID=com.example* 内部依赖版本更新到最新版本的功能。这是使用 Jenkins
我是 Kotlin 应用程序开发的初学者。当我尝试构建应用程序时发生以下错误 - e: C:/Users/Lenovo/.gradle/caches/transforms-2/files-2.1/32
我正在尝试安装一个名为 metaBIT 的程序。我能够将它添加到我的路径中。但是当我执行时: metaBIT -h 它出错并给我这个: Traceback (most recent call last
在使用选项 -smt2 -in 启动 Z3 后,我可以获取 Z3 的版本吗?有点像 (get-z3-version) ; Z3 4.3.2 x64 // Desired reply 最佳答案 在SM
这个问题在这里已经有了答案: What is the difference between Version and 'Runtime Version' in .Net? (1 个回答) 关闭 9 年
new Version(AssemblyFileVersionAttribute.Version) 总是会成功吗? 这是我的代码。 Contract.Ensures(Contract.Result()
我正在尝试针对另一个使用 libcurl 共享库的共享库 (libtheirstuff.so) 交叉编译我自己的共享库 (libmystuff.so),但出现以下错误: libmystuff.so:
在 Bazaar 中,如果您在 foo.html 中有冲突,它将生成额外的 3 个文件 foo.html.BASE foo.html.OTHER foo.html.THIS 那么你可以 diff -N
我的 java 7 和 java 8 都安装在我的 Windows 系统的 C:\Program Files\Java 下 在环境的路径中我像这样指定了java 7的路径。 %JAVA_HOME%/b
#version 330 和 #version 330 core 有什么区别? 核心重要吗? 最佳答案 这两个版本声明是等价的。 核心 是默认值。来自 GLSL 3.30 规范: If no prof
我是一名优秀的程序员,十分优秀!