Andrey Devyatka4 years agoPermalinkraw Messagehi,
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::d atabase* 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::d atabase* createdb (void)
{
ODB::d atabase* db = new odb::sqlite::d atabase ("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::d atabase* 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,
Andreyboris Kolpackov4 years agoPermalinkraw Messagehi Andrey,
Post by Andrey Devyatka
[...] This was 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 of the schema creation Code does not end with the executable.
Normally this isn't a problem since most application executables
Would also include code that persists objects, etc., which'll
The linker to include all of the object files from the library.
In your test, however, and all of you are create the schema. As mentioned
In the above e-mail, 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-lodbg++-o test2 main.o-wl,-whole-archive library.a-wl,-no-whole-archive- Lodb-sqlite-lodb
Another thing that your may find useful are the ' separate ' value for
The--schema-format option. It would 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.
Borisandrey Devyatka4 years agoPermalinkraw Messagethank you!
...--
Суважением,
А.п.девятка. From:http://odb-users.codesynthesis.narkive.com/3ms11hiv/create-schema-error-unknown-database-schema
Create schema Error (Unknown database schema ")