我已經搜索了一些日子,嘗試了幾個建議,但沒有任何幫助。目前我只想創建一個連接到Oracle數據庫的小Go代碼片段。雖然一切工作通過使用正常的go build
並調用生成的動態鏈接的應用程序,但當我嘗試運行靜態編譯器時,卡住了。我已經靜態構建了其他項目(即使使用CGO)也沒有問題,但是這裏gcc沒有找到oracle庫。也許有人有提示?構建過程中試圖在Linux/Ubuntu上使用Oracle庫構建靜態CGO可執行文件
錯誤:
host link: "gcc" "-m64" "-gdwarf-2" "-o" "/tmp/go-build319417544/command-line-arguments/_obj/exe/a.out" "-static" "/tmp/go-link-116023228/000000.o" "/tmp/go-link-116023228/000001.o" "/tmp/go-link-116023228/000002.o" "/tmp/go-link-116023228/go.o" "-g" "-O2" "-g" "-O2" "-lpthread" "-g" "-O2" "-L/usr/lib/oracle/12.1/client64/lib" "-lclntsh" "-static"
/home/hannes/.gvm/gos/go1.5/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: cannot find -lclntsh
collect2: error: ld returned 1 exit status
生成命令
CGO_ENABLED=1 go build -work -x -ldflags " -v -linkmode external -extldflags -static" ${MAIN_SRC}
施藥代碼:
package main
/*
// #cgo CFLAGS: -I/usr/lib/oracle/12.1/client64/include
// #cgo LDFLAGS: -L/usr/lib/oracle/12.1/client64/lib -lclntsh
*/
import "C"
import (
"fmt"
"database/sql"
_ "github.com/mattn/go-oci8"
"time"
)
func main(){
db, err := sql.Open("oci8", "...")
...
}
我與
dconfig -p | grep cln
libkadm5clnt_mit.so.9 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libkadm5clnt_mit.so.9
libclntshcore.so.12.1 (libc6,x86-64) => /usr/lib/oracle/12.1/client64/lib/libclntshcore.so.12.1
libclntshcore.so (libc6,x86-64) => /usr/lib/oracle/12.1/client64/lib/libclntshcore.so
libclntsh.so.12.1 (libc6,x86-64) => /usr/lib/oracle/12.1/client64/lib/libclntsh.so.12.1
libclntsh.so (libc6,x86-64) => /usr/lib/oracle/12.1/client64/lib/libclntsh.so
檢查
動態建立可執行文件(只是「去打造oracle_test.go)有它需要的一切:
ldd oracle_test
linux-vdso.so.1 => (0x00007ffeac867000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f083ef82000)
libclntsh.so.12.1 => /usr/lib/oracle/12.1/client64/lib/libclntsh.so.12.1 (0x00007f083bfc5000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f083bbfa000)
/lib64/ld-linux-x86-64.so.2 (0x00005615b32e8000)
libmql1.so => /usr/lib/oracle/12.1/client64/lib/libmql1.so (0x00007f083b984000)
libipc1.so => /usr/lib/oracle/12.1/client64/lib/libipc1.so (0x00007f083b606000)
libnnz12.so => /usr/lib/oracle/12.1/client64/lib/libnnz12.so (0x00007f083aefb000)
libons.so => /usr/lib/oracle/12.1/client64/lib/libons.so (0x00007f083acb6000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f083aab2000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f083a7a9000)
libnsl.so.1 => /lib/x86_64-linux-gnu/libnsl.so.1 (0x00007f083a58f000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f083a387000)
libaio.so.1 => /lib/x86_64-linux-gnu/libaio.so.1 (0x00007f083a184000)
libclntshcore.so.12.1 => /usr/lib/oracle/12.1/client64/lib/libclntshcore.so.12.1 (0x00007f0839c12000)
我也試圖把/出口CGO_LDFLAGS和/ ORD LD_LIBRARY_PATH環境變量,它並沒有幫助。
pkg配置說明以及
pkg-config --libs oci8
-L/usr/lib/oracle/12.1/client64/lib -lclntsh
尋找靜態庫後,我已經安裝了該庫的完整的Oracle數據庫包,現在我有lib文件夾一些文件: ls /usr/lib/oracle/12.1/client64/lib/lib*.a
-rw-r--r-- 1 1424782 /usr/lib/oracle/12.1/client64/lib/libagent12.a -rw-r--r-- 1 1962088 /usr/lib/oracle/12.1/client64/lib/libasmclnt12.a -rw-r--r-- 1 2187864 /usr/lib/oracle/12.1/client64/lib/libasmclntsh12.a -rw-r--r-- 1 11386 /usr/lib/oracle/12.1/client64/lib/libasmperl12.a -rw-r--r-- 1 28454 /usr/lib/oracle/12.1/client64/lib/libavstub12.a -rw-r--r-- 1 7408322 /usr/lib/oracle/12.1/client64/lib/libcell12.a -rw-r--r-- 1 11246008 /usr/lib/oracle/12.1/client64/lib/libclient12.a -rw-r--r-- 1 0 /usr/lib/oracle/12.1/client64/lib/libclntst12.a -rw-r--r-- 1 1749282 /usr/lib/oracle/12.1/client64/lib/libclsr12.a -rw-r--r-- 1 10087032 /usr/lib/oracle/12.1/client64/lib/libcommon12.a -rw-r--r-- 1 5803698 /usr/lib/oracle/12.1/client64/lib/libcore12.a -rw-r--r-- 1 6051402 /usr/lib/oracle/12.1/client64/lib/libctx12.a -rw-r--r-- 1 1201840 /usr/lib/oracle/12.1/client64/lib/libctxc12.a -rw-r--r-- 1 56964 /usr/lib/oracle/12.1/client64/lib/libctxs12.a ...snipped...
由於看到一個文件具有零大小,所以我必須運行$ ORACLE_HOME/bin/genclntst來生成libclntst12.a。
如果'/ usr/lib/oracle/12沒有顯示。1/client64/lib /'包含你需要的所有東西的靜態庫(或者如果系統具有靜態版本的依賴關係,但更可能) – JimB
嗨,我不得不承認,編譯時我沒有太多的知識靜態程序。所以,這裏是我的目錄: 'LS /usr/lib/oracle/12.1/client64/lib/ glogin.sql中 libclntsh.so libclntsh.so.12.1 libclntshcore.so libclntshcore.so.12.1 libipc1。所以 libmql1.so libnnz12.so libocci.so libocci.so.12.1 libociei.so libocijdbc12.so libons.so liboramysql12.so libsqlplus.so libsqlplusic.so ojdbc6.jar ojdbc7。罐子 ottclasses.zip xstreams.jar ' – hanneslehmann