SQL> select * from v$version;
+---------------------------------------------------------------------------------+
| BANNER |
+---------------------------------------------------------------------------------+
| DM Database Server 64 V8
|
| DB Version: 0x7000b |
+---------------------------------------------------------------------------------+
SQLRowCount returns 2
2 rows fetched
如果 isql 可以成功连接DB,并能执行测试语句,说明 UnixODBC 配置成功。
这里简单介绍几个Docker命令,熟悉Docker的同学可以跳过这一趴:
docker commit e9f39c7081e0 unixodbc001
说明:
e9f39c7081e0: 正在运行的容器ID,可以使用 docker ps 查看
unixodbc001:自定义的镜像名称
docker tag unixodbc001 registry.cn-beijing.aliyuncs.com/liutongtong/unixodbc001:V0.1
docker push registry.cn-beijing.aliyuncs.com/liutongtong/unixodbc001:V0.1
说明:像镜像仓库中提交该镜像,以后用的时候,直接拉取即可。
现实往往是残酷的,上面简单的几步中可能会遇到许多问题。
我把自己在安装过程中踩的坑,报的错及解决方案列在下面,供大家参考:
使用源码编译安装UnixODBC:
按照里面的步骤进行源码安装。最先遇到的问题是:
=> configure 时报错:cannot guess build type
./configure
UNAME_MACHINE = aarch64
UNAME_RELEASE = 4.4.131-20200704.kylin.server-generic
UNAME_SYSTEM = Linux
UNAME_VERSION = #kylin SMP Sat Jul 4 19:29:27 CST 2020
configure: error: cannot guess build type; you must specify one
解决办法:./configure --build=arm
=> 无法编译出 .so文件</font>
即便增加enable-shared也无法解决问题
./configure --build=arm --enable-shared
编译出来的始终是 .a 和 .la 文件。
尝试手动合成 .so
root@greatwall-os:/usr/local/lib# ar -x libodbcinst.a
root@greatwall-os:/usr/local/lib# gcc -shared *.o -o libodbcinst.so
报错:
/usr/bin/ld: libltdlc_la-ltdl.o: relocation R_AARCH64_ADR_PREL_PG_HI21 against external symbol `__stack_chk_guard@@GLIBC_2.17' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: libltdlc_la-ltdl.o(.text+0x6e4): 无法解决 R_AARCH64_ADR_PREL_PG_HI21 重定向于符号 “__stack_chk_guard@@GLIBC_2.17” 有冲突
/usr/bin/ld: 最后的链结失败: 错误的值
collect2: error: ld returned 1 exit status
解决办法:清除现有 odbc,增加 configure 参数后重新安装
make uninstall && make clean
CFLAGS="-fPIC" ./configure --build=arm
# 编译出来还是 .a ,但是这回 .a 是可以合并成 .so 的
ar -x /usr/local/lib/libodbc.a
gcc -shared *.o -o libodbc.so
=> could not determine kind of name for C.SQL_WLONGVAR
之前用的UnixODBC2.21版本过低,升级到2.3.2即可解决问题
=> isql 时报 file not found
[root@dameng-test001 dameng]# isql -v DM8 SYSDBA SYSDBA
[01000][unixODBC][Driver Manager]Can't open lib '/home/dmdba/dmdbms/bin/libdodbc.so' : file not found
使用 ls -l /home/dmdba/dmdbms/bin/libdodbc.so 命令可以看到文件存在,且权限为可访问。
root@Kylin:/Users/liutongtong/go/src/dameng-test/main# go run beego-orm.go
# github.com/alexbrainman/odbc/api
/usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld: cannot find -lodbc
/usr/lib/gcc-cross/arm-linux-gnueabi/8/../../../../arm-linux-gnueabi/bin/ld: cannot find -lodbc
使用 ld 命令查看:
root@Kylin:/Users/liutongtong/go/src/dameng-test/main# ld /usr/local/lib/libodbc.so
ld: warning: cannot find entry symbol _start; not setting start address
ld: /usr/local/lib/libodbc.so: undefined reference to `dlopen'
ld: /usr/local/lib/libodbc.so: undefined reference to `dlclose'
ld: /usr/local/lib/libodbc.so: undefined reference to `dlerror'
ld: /usr/local/lib/libodbc.so: undefined reference to `dlsym'
按照网上搜索来的方法进行尝试:
重新编译:
./configure LIBS=-ldl CFLAGS=-fno-strict-aliasing --build=arm
configure的时候提示:
checking for shl_load... (cached) no
checking for shl_load in -ldld... (cached) no
checking for dld_link in -ldld... no
checking for _ prefix in compiled symbols... no
尝试:
root@Kylin:/usr/local/lib# ar -x libodbcinst.a
root@Kylin:/usr/local/lib# gcc -shared *.o -o libodbcinst.so -ldl
之后 ld 报错:
root@Kylin:/Users/liutongtong/go/src/dameng-test/main# ld /usr/local/lib/libodbc.so
ld: warning: cannot find entry symbol _start; not setting start address