Note that there are some explanatory texts on larger screens.

plurals
  1. POodb/pgsql/version.hxx no such file or directory
    text
    copied!<p>I'm trying to learn how to use C++ and ODB following this tutorial:</p> <pre><code>http://www.codesynthesis.com/products/odb/doc/manual.xhtml#2 </code></pre> <p>I've created a Person.hxx file where there is the declaration of class Person as persistent, then I've got thre files Person-odb: .cxx, .hxx, .ixx</p> <p>Now I should compile Person-odb.cxx with </p> <pre><code>g++ -I/usr/lib/odb/i686-linux-gnu/include Person-odb.cxx </code></pre> <p>but it end with:</p> <pre><code>fatal error: odb/pgsql/version.hxx: No such file or directory. compilation terminated. </code></pre> <p>I see that there is a file version.hxx but there's no odb/pgsql directory... what's wrong?</p> <p>this is Person.hxx where I have defined the persistent class Person:</p> <pre><code>#ifndef PERSON_HXX #define PERSON_HXX #include &lt;string&gt; #include &lt;odb/core.hxx&gt; 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&amp; first, const std::string&amp; last, unsigned short age); /* getters */ const std::string&amp; first() const; const std::string&amp; last() const; unsigned short age() const; const std::string&amp; email() const; /* setters */ void setAge(unsigned short); void setFirst(const std::string&amp;); void setLast(const std::string&amp;); void setEmail(const std::string&amp;); }; #endif </code></pre> <p>then I must compile Person.hxx with odb compiler:</p> <pre><code>odb -d mysql --generate-query --generate-schema Person.hxx </code></pre> <p>and I get 4 files Person.odb.hxx, .cxx, .sql, .ixx this is driver.cxx where I have the main program which persists objects:</p> <pre><code>#include &lt;memory&gt; #include &lt;iostream&gt; #include &lt;odb/database.hxx&gt; #include &lt;odb/transaction.hxx&gt; #include &lt;odb/mysql/database.hxx&gt; #include "Person.hxx" #include "Person-odb.hxx" using namespace std; using namespace odb; int main(int argc, char* argv[]) { try { auto_ptr&lt;database&gt; 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-&gt;begin()); marcoID = db-&gt;persist(marco); lucaID = db-&gt;persist(luca); loryID = db-&gt;persist(lory); t.commit(); } catch (const odb::exception&amp; e) { cerr &lt;&lt; e.what() &lt;&lt; endl; return 1; } } </code></pre> <p>and this is the file Person-odb.hxx</p> <pre><code>// This file was generated by ODB, object-relational mapping (ORM) // compiler for C++. // #ifndef PERSON_ODB_HXX #define PERSON_ODB_HXX #include &lt;odb/version.hxx&gt; #if (ODB_VERSION != 20200UL) #error ODB runtime version mismatch #endif #include &lt;odb/pre.hxx&gt; #include "Person.hxx" #include &lt;memory&gt; #include &lt;cstddef&gt; #include &lt;odb/core.hxx&gt; #include &lt;odb/traits.hxx&gt; #include &lt;odb/callback.hxx&gt; #include &lt;odb/wrapper-traits.hxx&gt; #include &lt;odb/pointer-traits.hxx&gt; #include &lt;odb/container-traits.hxx&gt; #include &lt;odb/no-op-cache-traits.hxx&gt; #include &lt;odb/result.hxx&gt; #include &lt;odb/simple-object-result.hxx&gt; #include &lt;odb/details/unused.hxx&gt; #include &lt;odb/details/shared-ptr.hxx&gt; namespace odb { // Person template &lt;&gt; struct class_traits&lt; ::Person &gt; { static const class_kind kind = class_object; }; template &lt;&gt; class access::object_traits&lt; ::Person &gt; { ... #include "Person-odb.ixx" #include &lt;odb/post.hxx&gt; #endif // PERSON_ODB_HXX </code></pre> <p>everything seems to work fine when I perform:</p> <pre><code>c++ -c Person-odb.cxx c++ -c driver.cxx </code></pre> <p>but in the end when I have to link all together with:</p> <pre><code>c++ -o driver driver.o Person-odb.o -lodb-mysql -lodb </code></pre> <p>I get:</p> <p>"undefined reference to `Person::Person(std::basic_string, std::allocator > const&amp;, std::basic_string, std::allocator > const&amp;, unsigned short)'"</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload