FROM --platform=linux/arm64 debian:buster-slim as deb RUNset -eux; \ if [ -e /etc/apt/sources.list ];then sed -ri 's/[a-zA-Z0-9.]+(debian.org|ubuntu.com)/mirrors.aliyun.com/g' /etc/apt/sources.list; fi; \ apt update; \ cd /tmp; \ apt download \ libodbc1 \ libltdl7 \ unixodbc-dev; \ mkdir -p /test/usr/local/lib_arm64 /test/usr/local/include_arm64; \ ls *.deb | whileread deb;do dpkg-deb -x $deb /opt/; done; \ find /opt; \ find /opt/usr/lib/ -not -type d -execcp -a {} /test/usr/local/lib_arm64 \; ; \ find /opt/usr/include/ -not -type d -execcp -a {} /test/usr/local/include_arm64 \; ; \ ls -l /test/usr/local/lib_arm64 /test/usr/local/include_arm64
FROM cr.loongnix.cn/library/debian:buster-slim as loong64_deb RUNset -eux; \ if [ -e /etc/apt/sources.list ];then sed -ri 's/[a-zA-Z0-9.]+(debian.org|ubuntu.com)/mirrors.aliyun.com/g' /etc/apt/sources.list; fi; \ apt update; \ cd /tmp; \ apt download \ libodbc1 \ unixodbc-dev \ odbcinst1debian2 \ #libltdl-dev \ libltdl7; \ mkdir -p /test/usr/local/lib_loong64 /test/usr/local/include_loong64; \ ls *.deb | whileread deb;do dpkg-deb -x $deb /opt/; done; \ find /opt; \ find /opt/usr/lib/ -not -type d -execcp -a {} /test/usr/local/lib_loong64 \; ; \ find /opt/usr/include/ -not -type d -execcp -a {} /test/usr/local/include_loong64 \; ; \ ls -l /test/usr/local/lib_loong64 /test/usr/local/include_loong64
FROM scratch COPY --from=deb /test /odbc COPY --from=loong64_deb /test /odbc
龙芯使用:
1 2 3
CC=loongarch64-linux-gnu-gcc CGO_CFLAGS='-g -O2 -I/usr/local/include_loong64' \ CGO_LDFLAGS='-g -O2 -L/usr/local/lib_loong64 -Wl,-rpath-link,/usr/local/lib_loong64 -lodbc' \ GOARCH=loong64 CGO_ENABLED=1 go build -a -o /xxx cmd/xxx
不加额外的 -Wl,-rpath-link,/usr/local/lib_loong64 就报错 warning: libltdl.so.7, needed by /usr/local/lib_loong64/libodbc.so, not found (try using -rpath or -rpath-link) :
1 2 3 4 5 6 7 8 9
/usr/local/go/pkg/tool/linux_amd64/link: running loongarch64-linux-gnu-gcc failed: exit status 1 /loongson-gnu-toolchain/bin/../lib/gcc/loongarch64-linux-gnu/8.3.0/../../../../loongarch64-linux-gnu/bin/ld: warning: libltdl.so.7, needed by /usr/local/lib_loong64/libodbc.so, not found (try using -rpath or -rpath-link) /loongson-gnu-toolchain/bin/../lib/gcc/loongarch64-linux-gnu/8.3.0/../../../../loongarch64-linux-gnu/bin/ld: /usr/local/lib_loong64/libodbc.so: undefined reference to `lt_dlclose' /loongson-gnu-toolchain/bin/../lib/gcc/loongarch64-linux-gnu/8.3.0/../../../../loongarch64-linux-gnu/bin/ld: /usr/local/lib_loong64/libodbc.so: undefined reference to `lt_dlerror' /loongson-gnu-toolchain/bin/../lib/gcc/loongarch64-linux-gnu/8.3.0/../../../../loongarch64-linux-gnu/bin/ld: /usr/local/lib_loong64/libodbc.so: undefined reference to `lt_dlopen' /loongson-gnu-toolchain/bin/../lib/gcc/loongarch64-linux-gnu/8.3.0/../../../../loongarch64-linux-gnu/bin/ld: /usr/local/lib_loong64/libodbc.so: undefined reference to `lt_dlinit' /loongson-gnu-toolchain/bin/../lib/gcc/loongarch64-linux-gnu/8.3.0/../../../../loongarch64-linux-gnu/bin/ld: /usr/local/lib_loong64/libodbc.so: undefined reference to `lt_dlsetsearchpath' /loongson-gnu-toolchain/bin/../lib/gcc/loongarch64-linux-gnu/8.3.0/../../../../loongarch64-linux-gnu/bin/ld: /usr/local/lib_loong64/libodbc.so: undefined reference to `lt_dlsym' collect2: error: ld returned 1 exit status