Andrey Devyatka
2013-05-31 12:58:17 UTC
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!
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
Regards,
Andrey