简体   繁体   中英

How do you properly install SOCI?

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.

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.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM