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

最新文章

  1. Java Annotation概述
  2. js_事件委托
  3. [转] Struts2入门示例教程
  4. (原)android补间动画(四)之插补器Interpolator
  5. 数据库连接JDBC和数据库连接池C3P0自定义的java封装类
  6. [转载] Python 列表(list)、字典(dict)、字符串(string)常用基本操作小结
  7. 两种高性能I/O设计模式(Reactor/Proactor)的比较
  8. Routed Events【pluralsight】
  9. AJAX一些基本知识点
  10. 重写DataGridViewColumn
  11. GitHub开源库排名一百的简单介绍,值得收藏!
  12. webServices
  13. iOS 如何优雅的处理“回调地狱Callback hell”(一) (上)
  14. XJOI网上同步训练DAY6 T1
  15. ResourceBundle读取中文properties文件问题
  16. AndroidUI 视图动画-混合动画效果 (AnimationSet)/动画效果监听
  17. CSS之box-sizing的用处简单介绍
  18. hdu 2609 How many 最小表示法
  19. 实验:企业级分布式存储应用与实战-mogilefs实现
  20. pyqt5 动画在QThread线程中无法运行问题

热门文章

  1. ruby 第五次作业 part 1(分类、排序)
  2. MyBaties 异常之 java.lang.UnsupportedOperationException
  3. Spring 事物注解属性
  4. ASP.NET MVC的帮助类HtmlHelper和UrlHelper
  5. 【01】emmet系列之基础介绍
  6. Android BGABadgeView:显示提示数字(2)
  7. ModelForm组件和forms组件补充
  8. JDK源码解析(一)ArrayList源码解析
  9. 3.2 符号表之二叉查找树BST
  10. springboot 关于第三方包 打包问题