7

I'm facing an annoying problem that has been holding me back from programming for some time. I intend to start a personal project in which I need to use a database to store certain information and I decided to use SQLite however I did not like the C-ish API so I came across SOCI wrapper in the SQLite wiki.

I went to the official SOCI website, read the documentation and decided to give it a go. I followed the instructions in the 'Installation' chapter of the documentation and after installing all requirements I compiled it and installed it with:

cmake -DWITH_BOOST=ON -DSOCI_TESTS=ON -DWITH_SQLITE3=ON
make
make test
sudo make install

All tests completed successfully however when trying to run (after compiling with g++ test.cpp -o1 -lsoci_core -lsoci_sqlite3) a program such as this one:

test.cpp:

#include "soci/soci.h"
#include "soci/sqlite3/soci-sqlite3.h"
#include <iostream>

int main()
{
    soci::session sql(soci::sqlite3, "testdb.db");

    return 0;    
}

I get an error saying: "Error while loading shared libraries: libsoci_sqlite3.so.3.1: cannot open shared object file: No such file or directory." but looking at the install log I can clearly see that the shared library is installed.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Mihai Bişog
  • 998
  • 9
  • 24
  • You definitely have sqlite3 installed? with the so in /usr/lib or other accessible location. – 111111 Dec 11 '11 at 20:22
  • I wouldn't download the install from the soci site, instead there's a github project for soci that had the most update to date and bug free version of soci: http://soci.git.sourceforge.net/git/gitweb.cgi?p=soci/soci – Jared Krumsie Dec 11 '11 at 20:29
  • @111111: Of course. Doing a 'locate libsqlite3 | grep /usr/lib' will show that it is there. – Mihai Bişog Dec 11 '11 at 20:31

2 Answers2

3

I believe I have found the issue. Doing a:

strace -e open ./1 2>&1 | grep soci

Outputs the following:

open("/usr/local/lib/libsoci_core.so.3.1", O_RDONLY) = 3
open("/lib/x86_64-linux-gnu/tls/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/tls/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/tls/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/tls/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64-linux-gnu/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/tls/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/tls/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/lib/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/tls/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/tls/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/x86_64/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/lib/libsoci_sqlite3.so.3.1", O_RDONLY) = -1 ENOENT (No such file or directory)
./1: error while loading shared libraries: libsoci_sqlite3.so.3.1: cannot open shared object file: No such file or directory

By looking at it you can clearly see that it searches /usr/local/lib/ only for soci_core whereas normally it should search for soci_sqlite3 as well. A quick and dirty hack that fixes the problem is to create a smylink to libsoci_sqlite3.so.3.1 in any of the other folders listed there but I'm quite sure that there is a better way of fixing it.

Mihai Bişog
  • 998
  • 9
  • 24
0

On your SOCI installation libs are located in /usr/local/lib64/

Following statement should work:

g++ test.cpp -o test -I/usr/local/include/soci -L/usr/local/lib64/ -lsoci_core -lsoci_sqlite3 \
-Wl,-rpath=/usr/local/lib64/

mpiliszcz
  • 397
  • 4
  • 5