[odb-users] error during linking process for hello world example
with sqlite database
Teererai Marange
selection989 at gmail.com
Thu Jun 25 00:04:34 EDT 2015
Found the solution:
For anyone else who has had the same problem, the hello world example
documentation doesnt mention that you need to actually define
person::person(std::string
const&, std::string const&, unsigned short) within a cpp file or actually
define it in person.hxx.
On Thu, Jun 25, 2015 at 3:41 PM, Teererai Marange <selection989 at gmail.com>
wrote:
> Thanks for the quick response, however I have encountered another issue.
> When I perform the linking once again with the command:
>
> g++ -o driver driver.o person-odb.o -lodb-sqlite -lodb -L\usr\local\lib
>
> The following error is returned:
>
> driver.o: In function `main':
> driver.cpp:(.text+0x76): undefined reference to
> `person::person(std::string const&, std::string const&, unsigned short)'
> driver.cpp:(.text+0x110): undefined reference to
> `person::person(std::string const&, std::string const&, unsigned short)'
> driver.cpp:(.text+0x1b3): undefined reference to
> `person::person(std::string const&, std::string const&, unsigned short)'
> collect2: error: ld returned 1 exit status
>
> The code for driver.cpp is shown below:
>
>
> // driver.cpp
> //
>
> #include <memory> // std::auto_ptr
> #include <iostream>
>
> #include <odb/database.hxx>
> #include <odb/transaction.hxx>
>
> #include <odb/sqlite/database.hxx>
>
> #include "person.hpp"
> #include "person-odb.hxx"
>
> using namespace std;
> using namespace odb::core;
>
> int
> main (int argc, char* argv[])
> {
> person john ("John", "Doe", 33);
> person jane ("Jane", "Doe", 32);
> person joe ("Joe", "Dirt", 30);
>
> transaction t (db->begin ());
>
> // Make objects persistent and save their ids for later use.
> //
> john_id = db->persist (john);
> jane_id = db->persist (jane);
> joe_id = db->persist (joe);
>
> t.commit ();
> }
> }
> catch (const odb::exception& e)
> {
> cerr << e.what () << endl;
> return 1;
> }
> }
>
> person.hpp is shown below:
>
>
> // person.hpp
> //
> #ifndef PERSON_HPP
> #define PERSON_HPP
>
> #include <string>
> #include <odb/core.hxx>
>
> #pragma db object
> class person
> {
> public:
> person (const std::string& first,
> const std::string& last,
> unsigned short age);
>
> const std::string& first () const;
> const std::string& last () const;
>
> unsigned short age () const;
> void age (unsigned short);
>
> private:
> person(){};
>
> friend class odb::access;
>
> #pragma db id auto
> unsigned long id_;
> std::string first_;
> std::string last_;
> unsigned short age_;
> };
>
> #endif
>
> I am new to linking in general so any assistance would be appreciated.
>
>
>
>
> On Thu, Jun 25, 2015 at 6:04 AM, Alexandre Pretyman <
> alexandre.pretyman at gmail.com> wrote:
>
>> You seem to be missing the argument to tell the linker to actually look
>> in /usr/local/lib: -L/usr/local/lib -lodb-mysql
>>
>> For more information, you can follow this link: http://bfy.tw/V1d =)
>>
>> On 24 June 2015 at 11:52, Teererai Marange <selection989 at gmail.com>
>> wrote:
>>
>>> In attempting to get the hello world example program from the
>>> documentation
>>> to work, I am failing to link the application using the following command
>>> entered in terminal:
>>>
>>> g++ -o driver driver.o person-odb.o -L/usr/local/lib/
>>> libodb-sqlite-2.4.so
>>> -lodb-mysql -lodb
>>>
>>> The following error is returned by terminal:
>>>
>>> /usr/bin/ld: cannot find -lodb-mysql
>>> collect2: error: ld returned 1 exit status
>>>
>>> Upon installation of libodb-sqlite-2.4, I was informed that the libraries
>>> were located in /usr/local/lib and can confirm that the shared objects do
>>> indeed exist there. In addition to this, I am using libodb-2.4 and am
>>> using
>>> g++ version 4.8.
>>>
>>>
>>>
>>> --
>>> Regards,
>>>
>>> Teererai Marange
>>>
>>
>>
>>
>> --
>> Alexandre Pretyman
>>
>
>
>
> --
> Regards,
>
> Teererai Marange
> Ph: 021521987
>
--
Regards,
Teererai Marange
Ph: 021521987
More information about the odb-users
mailing list