1

I'm working on an embedded platform and I am trying to access a MariaDB through unixODBC. Trying to test the connection with isql I get the response:

isql -v mydsn myuser mypw
[01000][unixODBC][Driver Manager]Can't open lib '/usr/lib/libmaodbc.so' : file not found

The file /usr/lib/libmaodbc.so exists:

ls -la /usr/lib/libmaodbc.so
-r-xr-xr-x    1 root     root        403952 Sep  1 00:00 /usr/lib/libmaodbc.so

So I figured a dependency must be missing.

readelf -d /usr/lib/libmaodbc.so 

Dynamic section at offset 0x4fb54 contains 30 entries:
  Tag        Type                         Name/Value
 0x00000001 (NEEDED)                     Shared library: [libodbcinst.so.2]
 0x00000001 (NEEDED)                     Shared library: [libm.so.6]
 0x00000001 (NEEDED)                     Shared library: [libc.so.6]
 0x00000001 (NEEDED)                     Shared library: [ld-linux-armhf.so.3]
 0x0000000e (SONAME)                     Library soname: [libmaodbc.so]
[...]

I repeated the check - all four dependencies exist.

Next I wrote a test program, which tries to load the shared objects:

#include <iostream>
#include <dlfcn.h>

void tryLoadSo(const std::string& path) {
    void* so = dlopen(path.c_str(), RTLD_NOW);
    if(so) {
        std::cout << "Loaded " << path << "!" << std::endl;
        dlclose(so);
    } else {
        std::cout << "Failed to load " << path << "!" << std::endl;
    }
}

int main() {
    tryLoadSo("/usr/lib/libmaodbc.so");
    tryLoadSo("/usr/lib/libodbcinst.so.2");
    tryLoadSo("/usr/lib/libm.so.6");
    tryLoadSo("/usr/lib/libc.so.6");
    tryLoadSo("/usr/lib/ld-linux-armhf.so.3");
}

Output:

Failed to load /usr/lib/libmaodbc.so!
Loaded /usr/lib/libodbcinst.so.2!
Loaded /usr/lib/libm.so.6!
Loaded /usr/lib/libc.so.6!
Loaded /usr/lib/ld-linux-armhf.so.3!

Thus all the dependencies can be loaded, but libmaodbc cannot.

Is the shared object not configured for the correct plattform? Yes, it is. I compared it to libodbcinst.so.2 to make sure:

readelf -h /usr/lib/libmaodbc.so 
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              DYN (Shared object file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x9a58
  Start of program headers:          52 (bytes into file)
  Start of section headers:          402952 (bytes into file)
  Flags:                             0x5000400, Version5 EABI, hard-float ABI
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         7
  Size of section headers:           40 (bytes)
  Number of section headers:         25
  Section header string table index: 24

readelf -h /usr/lib/libodbcinst.so.2
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              DYN (Shared object file)
  Machine:                           ARM
  Version:                           0x1
  Entry point address:               0x1e60
  Start of program headers:          52 (bytes into file)
  Start of section headers:          53528 (bytes into file)
  Flags:                             0x5000400, Version5 EABI, hard-float ABI
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         6
  Size of section headers:           40 (bytes)
  Number of section headers:         24
  Section header string table index: 23

What could be going wrong? Why won't libmaodbc.so load?

| improve this question | | | | |
0

libmaodbc.so was linked statically against libmariadb.so.3. Now I linked libmariadb.so.3 dynamically and it worked.

No idea if a bad/unmatching library was linked or some other settings for linking were not correct (maybe something not ok in CMakeLists.txt?). So I still don't understand the root cause. But the symptom is fixed.

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.