Andrey Devyatka
4 years ago
Permalink

Raw Message

Hi,
Please tell me, can I use the static library in the following case:

library.hpp:
#ifndef _CPP_ODB_STATIC_LIBRARY_CPP_
#define _CPP_ODB_STATIC_LIBRARY_CPP_
#include <odb/database.hxx>
odb::database* createDb(void);
#pragma db object
struct Test
{
#pragma db id auto
int m_id;
};
#endif // _CPP_ODB_STATIC_LIBRARY_CPP_

library.cpp:
#include <odb/sqlite/database.hxx>
#include <odb/transaction.hxx>
#include <odb/schema-catalog.hxx>
#include "library.hpp"
odb::database* createDb(void)
{
odb::database* db = new odb::sqlite::database("test.db",
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE);
odb::transaction t(db->begin());
odb::schema_catalog::create_schema(*db);
t.commit();
return db;
}

main.cpp:
include <iostream>
#include <odb/exception.hxx>
#include "library.hpp"
int main()
{
try {
odb::database* db = createDb();
std::cout << "SUCCESS" << std::endl;
}catch(const odb::exception& ex){
std::cout << "ERROR: " << ex.what() << std::endl;
}
}

build:
$ odb --database sqlite --generate-schema library.hpp
$ g++ -c library-odb.cxx library.cpp main.cpp
$ ar cr library.a library.o library-odb.o
$ g++ -o test1 library.o library-odb.o main.o -lodb-sqlite -lodb
$ g++ -o test2 main.o library.a -lodb-sqlite -lodb

test:
$ ./test1
SUCCESS
$ ./test2
ERROR: unknown database schema ''

misc:
$ uname -srm
Linux 3.8.0-23-generic x86_64
$ g++ --version | head -n1
g++ (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3
$ odb --version | head -n1
ODB object-relational mapping (ORM) compiler for C++ 2.2.0

Thanks!

--
Regards,
Andrey
Boris Kolpackov
4 years ago
Permalink

Raw Message

Hi Andrey,

This is exactly the same issue that we've discussed just a few days
ago:

http://www.codesynthesis.com/pipermail/odb-users/2013-May/001286.html

Because your application doesn't directly reference any symbols from
library-odb.cxx, the linker ignores library-odb.o from library.a. As
a result the schema creation code does not end up in the executable.

Normally this is not a problem since most application executables
will also include code that persists objects, etc., which will
force the linker to include all the object files from the library.

In your test, however, all you do is create the schema. As mentioned
in the above email, with GNU ld you can use the --whole-archive
option to force the linker to include every object file from your

Post by Andrey Devyatka
$ g++ -o test2 main.o library.a -lodb-sqlite -lodb

g++ -o test2 main.o -Wl,-whole-archive library.a -Wl,-no-whole-archive -lodb-sqlite -lodb

Another thing that you may find useful is the 'separate' value for
the --schema-format option. It will trigger the generation of the
schema creation code as a separate C++ source file (library-schema.cxx).
You can then perhaps link it directly to your executable instead of
packaging it into a static library. See the ODB compiler command line
documentation (man pages) for more information on this option.

Boris

Andrey Devyatka
4 years ago
Permalink

Raw Message

Thank you!

...
--
С уважением,
А. П. Девятка.
 
from:http://odb-users.codesynthesis.narkive.com/3Ms11hIV/create-schema-error-unknown-database-schema

Create schema error (unknown database schema '')的更多相关文章

  1. [odb-users] Create schema error (unknown database schema '')

    Boris Kolpackov boris at codesynthesis.comFri May 31 11:13:02 EDT 2013 Previous message: [odb-users] ...

  2. Could not update Activiti database schema: unknown version from database: '5.20.0.1'

    转: Could not update Activiti database schema: unknown version from database: '5.20.0.1' 2017年11月22日 ...

  3. database schema

    数据中有4个Schema无法被删除 ● dbo, 具有db_owner或者db_ddl_admin 的用户,新创建对象默认schema就是dbo ● guest , 用来给guest 用户使用,这个s ...

  4. SQL Server中删除用户时报错,提示:The database principal owns a schema in the database, and cannot be dropped(转载)

    Description of the problem: When you tried to drop a user, you got this message: Error: 15138 The da ...

  5. HiveSQLException: Error while compiling statement: No privilege 'Create' found for outputs { database:default }

    今天用Hive的JDBC实例时出现了HiveSQLException: Error while compiling statement: No privilege 'Create' found for ...

  6. MySQL的登陆错误:ERROR 1049 (42000): Unknown database 'root'

    当初刚装MySQL的时候,到网上查的命令行登陆MySQL的方法都是mysql -u root -p password mysql -r root -p 123456 但是奇怪的是这条命令我输进去死活都 ...

  7. org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Unknown database 'jdsc')

    org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Unknown databas ...

  8. mysqldump: [ERROR] unknown variable 'database=test'.

    背景: 导出数据库test库的test表数据出现报错信息:mysqldump: [ERROR] unknown variable 'database=test'. 原来是my.cnf参数文件配置了以下 ...

  9. [笔记] MySql Workbench 导出表结构和数据报错 mysqldump: [ERROR] unknown variable 'delayed-insert=FALSE'

    下午使用MySql Workbench导出数据库表结构,设置完导出选项后执行导出,报如下错误: :: Dumping nacweixindb (tb_app) Running: mysqldump.e ...

随机推荐

  1. 经典卷积网络VGG,GoodLeNet,Inception

    目录 ImageNet LeNet-5 LeNet-5 Demo AlexNet VGG 1*1 Convolution GoogLeNet Stack more layers? ImageNet L ...

  2. MySQL-----删

    删 **清空数据库内容** delete from 数据库表名; ----清内容,但是自增列的数不清. truncate table 数据库表名; --------自增列的数也清. **清除指定的行数 ...

  3. HUAS Summer Contest#4 D题 DP

    Description Speakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要准备的材料,于是,便需要去申请学校了.要申请国外的任何大学,你都要交纳一定的申请费用,这可是很惊人的 ...

  4. phtyon,通过while循环简单的用户名和密码登录

    _username='zhangxin' _password='abc123' _username1='zhaopeng' _password1='abc1234' _username2=" ...

  5. IDEA的Maven Projects无法显示

    记一个小坑: 前两天重装了一下电脑系统,下载了个最新的IDEA2018.3.5,把Maven.JDK.TomCat都设置好了 今天打开IDEA创建一个新的Maven项目,项目没有显示让我导入Maven ...

  6. 关于SQL Server 的限制

    经常被人问到关于SQL Server 的连接数限制, 或者最大的文件大小, 或者标准版和企业版的区别,以及Express上的 其实这些问题都可以在MSDN 上直接找到 SQL Server 2014 ...

  7. MySQL最优配置文件模板·2016-11-28

    小伙伴们大爱的MySQL最优配置文件模板更新啦.对之前的MySQL最优配置文件·20160901做了一些修正,更为名至实归.可以通过此链接进行下载.当然,更欢迎同学们提出意见和建议,共同打造一个最优M ...

  8. linux 下CPU数量、核心数量、是否支持超线程的判断

    判断依据:1.具有相同core id的cpu是同一个core的超线程.2.具有相同physical id的cpu是同一颗cpu封装的线程或者cores. 英文版:1.Physical id and c ...

  9. fd最大值和限制

    fd的数量决定了fd的最大值 在Linux下,系统全部能够打开的fd总数为: /proc/sys/fs/file-max,取决于内存 The file-max file /proc/sys/fs/fi ...

  10. POJ 1330 (LCA)

    http://poj.org/problem?id=1330 题意:给出一个图,求两个点的最近公共祖先. sl :水题,贴个模板试试代码.本来是再敲HDU4757的中间发现要用LCA,  操蛋只好用这 ...