2016-07-15 96 views
1

我編譯下面的C時,遇到了一個錯誤,不承認「*」的矩陣乘法++代碼:克++編譯使用犰狳庫

# include <iostream> 
# include <armadillo> 

using namespace arma; 
using namespace std; 

int main() { 
mat A; 
mat B; 
mat C; 

// Populating the matrices with random numbers 
A.randu(3,3); 
B.randu(3,3); 

// Matrix multiplication 
C = A * B; 

cout << "Mutliplying matrices A and B:" << endl; 
cout << "A * B = " << C << endl; 

return 0; 

}

這裏是我的錯誤使用g ++編譯時:

Undefined symbols for architecture x86_64: "_wrapper_dgemm_", referenced from:

void arma::blas::gemm<double>(char const*, char const*, int const*, > int const*, int const*, double const*, double const*, int const*, double > const*, int const*, double const*, double*, int const*) in >armadillo_playground-aa3649.o 

"_wrapper_dgemv_", referenced from:

void arma::blas::gemv<double>(char const*, int const*, int const*, >double const*, double const*, int const*, double const*, int const*, >double const*, double*, int const*) in armadillo_playground-aa3649.o 

ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see >invocation)

當我替換矩陣乘法「*」與「+」,「%」,等等的代碼編譯沒有抱怨。

在此先感謝!

+0

看起來'*'運算符的定義在源文件中,而且你沒有鏈接庫? –

+0

哎呀,我不知道在圖書館連接。但是,現在我遇到了以下錯誤:dyld:Library not loaded:/usr/local/opt/gcc/lib/gcc/6/libgfortran.3.dylib 引用自:/ usr/local/opt/arpack/libexec/lib/libarpack.2.dylib 原因是:image not found Trace/BPT陷阱:5 –

+0

也許這有幫助嗎? http://stackoverflow.com/questions/24993752/os-x-framework-library-not-loaded-image-not-found –

回答

0

錯誤是一個簡單的鏈接器錯誤,您可以通過正確構建來克服。正是你所需要將取決於你的系統/ OS(並且所有的記錄),但在我的Linux機器工作原理:

[email protected]:/tmp$ g++ -o arma arma.cpp -larmadillo 
[email protected]:/tmp$ ./arma 
Mutliplying matrices A and B: 
A * B = 1.0574 1.0356 1.5178 
    1.1368 1.3434 1.4919 
    0.7028 0.6516 1.0423 

[email protected]:/tmp$ 

這裏arma.cpp是包含您的示例文件。鏈接到libarmadillo.so庫就足夠了,因爲它鏈接到LAPACK和BLAS庫。其他操作系統可能有不同的使用模式。

+0

感謝您的輸入,Dirk。我是初學者,仍然有一些問題。我一直卡住,所以我決定卸載並重新安裝使用自制軟件。在brew安裝後,我將其更改爲目錄'/usr/local/Cellar/armadillo/7.200.2',並嘗試按照readme.txt中的指示運行CMake。我現在遇到這個錯誤:目錄不包含CMakeLists.txt。 –

+0

@ToddYoung - 在使用Homebrew安裝Armadillo之後,您不需要再使用CMake安裝它。 – mtall