cancel
Showing results for 
Search instead for 
Did you mean: 

connection to SQL Anywhere 17 with C++

Former Member
0 Kudos
2,024

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");

try {

//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 ?

Vlad
Product and Topic Expert
Product and Topic Expert
0 Kudos

Can you please check what the command below returns?

ldconfig -v

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.

Former Member
0 Kudos

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:


Failed to initialize the interface! Supported version=5
Compiling, linking and testing on the command line:

compile
…
$ g++ -g -Wall -std=c++14 -c -lboost_thread -DBOOST_THREAD_VERSION=4 -pthread sa_connect_test.cpp
link
$ 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
test
$ ./sa_connect_test 
Row : x = 2, y = 'Port'
$ echo $LD_LIBRARY_PATH 
/opt/sqlanywhere17/lib64:/home/bluefrog/SQLAPI/lib
But when I use ldconfig instead, i.e.

$ cd /etc/ld.so.conf.d
$ sudo vi sqlanywhere.conf
add the following line
/opt/sqlanywhere17/lib64

$ sudo ldconfig

now, compile & link in Geany IDE, I get the following error message: Failed to initialize the interface! Supported version=5

ldconfig output is $ sudo ldconfig -v | grep "sqlanywhere17" /sbin/ldconfig.real: Path /lib/x86_64-linux-gnu' given more than once /sbin/ldconfig.real: Path/usr/lib/x86_64-linux-gnu' given more than once /opt/sqlanywhere17/lib64: /sbin/ldconfig.real: /lib/x86_64-linux-gnu/ld-2.24.so is the dynamic linker, ignoring

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.


$ LD_LIBRARY_PATH="/opt/sqlanywhere17/lib64:/home/bluefrog/SQLAPI/lib" geany

The issue seems to be ldconfig cache. Ay suggestions on how to ensure the lib64 directory is specified and accessed correctly in the cache?

Accepted Solutions (0)

Answers (0)