unixODBC:无法加载 libmaodbc.so

unixODBC:无法加载 libmaodbc.so

我正在开发一个嵌入式平台,并尝试通过 unixODBC 访问 MariaDB。尝试测试与 isql 的连接我得到响应:

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

文件 /usr/lib/libmaodbc.so 存在:

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

所以我认为一定缺少依赖项。

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]
[...]

我重复了检查 - 所有四个依赖项都存在。

接下来我编写了一个测试程序,它尝试加载共享对象:

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

输出:

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!

因此可以加载所有依赖项,但 libmaodbc 不能。

共享对象是否未配置正确的平台?是的。我将它与 libodbcinst.so.2 进行了比较,以确保:

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

可能出了什么问题?为什么 libmaodbc.so 无法加载?

答案1

libmaodbc.so 与 libmariadb.so.3 静态链接。现在我动态链接 libmariadb.so.3 并且它起作用了。

不知道是否链接了错误/不匹配的库或其他一些链接设置不正确(也许 CMakeLists.txt 中有些问题?)。所以我还是不明白根本原因。但症状是固定的。

相关内容