我試圖將OpenCV 3.2.0作爲iOS應用程序內部的靜態庫來實現。我已經創建了一個opencv.xcodeproj
項目我的工作區中建立靜態庫,我然後鏈接到我的主要應用程序的項目,就像這樣:OpenCV 3.2.0 iOS類型轉換:int to __CLPK_integer *
文件hal_internal.cpp
在opencv_core
不會編譯由於類型轉換錯誤。這是問題的代碼的一個樣本,縮短:
lapack_LU(fptype* a, size_t a_step, int m, fptype* b, size_t b_step, int n, int* info)
{
int lda = (int)(a_step/sizeof(fptype)), sign = 0;
int* piv = new int[m];
transpose_square_inplace(a, lda, m);
if(b)
{
if(n == 1 && b_step == sizeof(fptype))
{
if(typeid(fptype) == typeid(float))
sgesv_(&m, &n, (float*)a, &lda, piv, (float*)b, &m, info);
}
}
}
編譯器錯誤是No matching function for call to sgesv_
因爲m
參數,這是一種int
是__CLPK_integer
類型不是。
這是函數簽名:
int sgesv_(__CLPK_integer *__n, __CLPK_integer *__nrhs, __CLPK_real *__a,
__CLPK_integer *__lda, __CLPK_integer *__ipiv, __CLPK_real *__b,
__CLPK_integer *__ldb,
__CLPK_integer *__info) __OSX_AVAILABLE_STARTING(__MAC_10_2,
__IPHONE_4_0);
__CLPK_integer
在clapack.h
定義在加速框架:
#if defined(__LP64__) /* In LP64 match sizes with the 32 bit ABI */
typedef int __CLPK_integer;
...
#else
typedef long int __CLPK_integer;
...
#endif
如果我嘗試創建一個緩存器並使用它來代替:
__CLPK_integer newM = m;
...
sgesv_(&newM, &n, (float*)a, &lda, piv, (float*)b, &m, info);
我得到相同的編譯器錯誤。
如果我嘗試
__CLPK_integer* newM = (int*)m;
...
sgesv_(newM, &n, (float*)a, &lda, piv, (float*)b, &m, info);
編譯器可以找到函數sgesv_
但在newM
聲明發出了一個錯誤:
Cannot initialize a variable of type '__CLPK_integer *' (aka 'long *') with an rvalue of type 'int *'
而且,爲什麼編譯器現在想想__CLPK_integer
是aka 'long *'
?
如果我試着轉換__CLPK_integer* newM = (long*)m;
,我得到了同樣的錯誤,但編譯器認爲__CLPK_integer是aka 'int *'
。
我對Generic iOS Device
和Build Active Architecture Only
設置爲是。
如何將int m
轉換爲預期的類型__CLPK_integer *
?
謝謝!
謝謝湯姆。永遠不要低估新鮮眼睛的力量。 我確實最終不得不施放所有參數。該呼叫現在看起來是這樣的: sgesv_( \t \t \t \t \t(__CLPK_integer *)&M, \t \t \t \t \t(__CLPK_integer *)&N, \t \t \t \t \t(浮動*)一個, \t \t \t \t \t(__CLPK_integer *)&lda, \t \t \t \t \t PIV, \t \t \t \t \t(浮子*)B, \t \t \t \t \t(__CLPK_integer *)&米, \t \t \t \t \t(__CLPK_integer *)&信息 \t \t \t \t \t); – Erwin