Please be aware that the SAP SQL Anywhere Forum will be shut down on August 29th, 2024 when all it's content will be migrated to the SAP Community.

I've been successfully using SQLAPI++ to connect and execute SQL statements against Oracle 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/ 
$ ./pg_connect_test 
Row : x = 1, y = 'Fill'
Row : x = 2, y = 'Pop'
$ ~/bin/ 

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/ 
$ ./sa_connect_test 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/ 
Bu the file does exist:

$ ls -l /opt/sqlanywhere17/lib64/
lrwxrwxrwx 1 bluefrog bluefrog 14 Jul 12 11:48 /opt/sqlanywhere17/lib64/ ->
and the LD_LIBRARY_PATH is set correctly

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);
    printf("Row : x = %ld, y = '%s'\n", cmd.Field("x").asLong(), (const char*)cmd.Field("y").asString());
catch(SAException &x) {
  try {
  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 ?

asked 12 Jul '17, 14:28

bluefrog's gravatar image

accept rate: 0%

edited 12 Jul '17, 14:29

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.

(13 Jul '17, 04:37) Vlad

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:

$ g++ -g -Wall -std=c++14 -c -lboost_thread -DBOOST_THREAD_VERSION=4 -pthread sa_connect_test.cpp
$ 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
$ ./sa_connect_test 
Row : x = 2, y = 'Port'
But when I use ldconfig instead, i.e.

$ cd /etc/
$ sudo vi sqlanywhere.conf
add the following line

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

(13 Jul '17, 10:50) bluefrog
Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 12 Jul '17, 14:28

question was seen: 1,939 times

last updated: 13 Jul '17, 10:52