苹果 M1 上 SQL Server 的 ODBC 驱动程序 17

问题描述

我正在尝试让 sql Server 的 ODBC 驱动程序 17 正常工作,但不知何故它在我全新的苹果 M1 上没有。 显然我安装了 unixodbc 和驱动程序,但启动它们不起作用。看起来 odbc 驱动程序还没有为架构做好准备(见下面的输出)。甚至看起来不像是微软驱动程序的问题,而是来自 unixodbc 的通用库——我说得对吗?

有什么想法可以自己编译吗?

XXX@M1 ~ % odbcinst -j
unixODBC 2.3.9
DRIVERS............: /opt/homebrew/etc/odbcinst.ini
SYstem DATA SOURCES: /opt/homebrew/etc/odbc.ini
FILE DATA SOURCES..: /opt/homebrew/etc/ODBCDataSources
USER DATA SOURCES..: /Users/XXX/.odbc.ini
sqlULEN Size.......: 8
sqlLEN Size........: 8
sqlSETPOSIROW Size.: 8
XXX@M1 ~ % sqlcmd
dyld: Library not loaded: /usr/local/lib/libodbc.2.dylib
  Referenced from: /opt/homebrew/bin/sqlcmd
  Reason: no suitable image found.  Did find:
    /usr/local/lib/libodbc.2.dylib: mach-o,but wrong architecture
    /usr/local/lib/libodbc.2.dylib: mach-o,but wrong architecture
    /opt/homebrew/Cellar/unixodbc/2.3.9/lib/libodbc.2.dylib: mach-o,but wrong architecture

解决方法

我不熟悉 odbcinst,但一般来说,从 Apple Silicon (M1) 上的终端运行时,如果库不是通用的,您有两种选择:

  1. 将终端设置为在 Rosetta2 上运行,或
  2. 在命令前加上 arch -x86_64

我建议你试试

arch -x86_64 odbcinst -j

阅读有关此 here 的更多信息。 (是的,链接中提到了 Flutter,但解决方案是一样的。)