開發平台(Platform): (Ex: Win10, Linux, ...)
Debian GNU/Linux Jessie
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
g++ 4.9.2
go 1.7.3
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
None
問題(Question):
我在練習將 Golang 轉出的 shared library 和 C++ 程式結合
程式已經寫好了,也轉成 shared library (.so)
編譯時也沒跳錯誤訊息,編譯指令如下:
$ g++ -o main main.cpp -L. -ldoubler
但是執行時,程式卻說找不到 shared library,訊息如下:
libdoubler.so: cannot open shared object file: No such file or directory
蠻詭異的,那個 .so 檔就在同一個資料夾中 Orz
我另外把這個程式包成 Ruby gem,給 Ruby 程式呼叫,可正確執行
我也在 Mac 上用同樣的 main.cpp,也可正確執行
這個蠻難 google 的,因為會找到一大堆沒裝 xxx library 之類的討論串 = =...
餵入的資料(Input):
None
預期的正確結果(Expected Output):
錯誤結果(Wrong Output):
./main: error while loading shared libraries:
libdoubler.so: cannot open shared object file: No such file or directory
程式碼(Code):(請善用置底文網頁, 記得排版)
# main.cpp
#include <iostream>
#include "libdoubler.h"
using std::cout;
using std::endl;
int main() {
cout << DoubleFloat(1.2) << endl;
}
如果大家有興趣,可以到以下網址看我的程式碼:
https://github.com/cwchentw/doubler
補充說明(Supplement):
PTT 惠我良多