I've been successfully using SQLAPI++ to connect and execute SQL statements against Oracle 11.2.0.4 and PostgreSQL 9.6.3.
I've had no joy with SQL Anywhere 17 however.
The g++ command I use is:
$ export LD_LIBRARY_PATH=/opt/sqlanywhere17/lib64:$LD_LIBRARY_PATH
$ g++ -g -Wall -std=c++14 -o sa_connect_test sa_connect_test.o /home/bluefrog/SQLAPI/lib/libsqlapi.a -L/usr/lib/x86_64-linux-gnu -lpthread -pthread -lboost_thread -DBOOST_THREAD_VERSION=4 -lboost_system -ldl -lpq
There are no compile or link errors.
Connection to PostgreSQL and execution of statements are successful
$ ~/bin/pgstart.sh
$ ./pg_connect_test
Row : x = 1, y = 'Fill'
Row : x = 2, y = 'Pop'
$ ~/bin/pgstop.sh
The same code, apart from the connect string returns the same result on Oracle (the same table name and data exists on all 3 databases).
Connection to SQL Anywhere however returns the following runtime error:
$ ~/bin/sastart.sh
$ ./sa_connect_test
libdbcapi.so: cannot open shared object file: No such file or directory
DBMS API Library loading fails
This library is a part of DBMS client installation, not SQLAPI++
Make sure DBMS client is installed and
this required library is available for dynamic loading
$ ~/bin/sastop.sh
Bu the file does exist:
$ ls -l /opt/sqlanywhere17/lib64/libdbcapi.so
lrwxrwxrwx 1 bluefrog bluefrog 14 Jul 12 11:48 /opt/sqlanywhere17/lib64/libdbcapi.so -> libdbcapi.so.1
and the LD_LIBRARY_PATH is set correctly
$ echo $LD_LIBRARY_PATH
/opt/sqlanywhere17/lib64:/home/bluefrog/SQLAPI/lib
The test code looks as follows:
include \<stdio.h>
include </home>
int main(int argc, char* argv[]) {
SAConnection con;
SACommand cmd(&con, "select x, y from test1");
//con.Connect("localhost,5432@ft_node", "bluefrog", "bluefrog", SA_PostgreSQL_Client);
//con.Connect("//localhost:1521/ftnode", "ordb", "ordb", SA_Oracle_Client);
con.Connect("localhost,2638@ftnode_sa", "sadb", "sadb", SA_SQLAnywhere_Client);
cmd.Execute();
while(cmd.FetchNext())
printf("Row : x = %ld, y = '%s'\n", cmd.Field("x").asLong(), (const char*)cmd.Field("y").asString());
}
catch(SAException &x) {
try {
con.Rollback();
}
catch(SAException &) { }
printf("%s\n", (const char*)x.ErrText());
}
return 0;
};
I do not understand why the library file is not been found. Any suggestion ?
Can you please check what the command below returns?
it should show you the list of cached libraries.
a stupid question, what if you copy the library to the same folder where your executable file is, will this help (at least temporary)?
you can try to check what libraries have been loaded using the link from SO.
When I compile and link on the command line, having set LD_LIBRARY_PATH correctly, everything works as expected. When I use an IDE such as Geany or Codeblocks I get an error message:
Compiling, linking and testing on the command line:
But when I use ldconfig instead, i.e.As soon as I revert back to the command line, everything works as expected.
ALternatively, if I set LD_LIBRARY_PATH and call geany from the command line, then it works as expected as well, i.e.
The issue seems to be ldconfig cache. Ay suggestions on how to ensure the lib64 directory is specified and accessed correctly in the cache?