2016-02-25 98 views
0

(注意:詳細信息已更新。)我試圖在我的機器上安裝mYm(運行OS X 10.11.3的MacBook Pro 15)。編譯在Matlab使用MEX:在Matlab中使用mex編譯C++失敗

> mex -I/usr/local/mysql/include -L/usr/local/mysql/lib mym.cpp;

不過,我得到了下面的錯誤,我不能解析:

Building with 'Xcode Clang++'. 
Error using mex 
Undefined symbols for architecture x86_64: 
    "_compress", referenced from: 
     _mexFunction in mym.o 
    "_compressBound", referenced from: 
     _mexFunction in mym.o 
    "_mysql_affected_rows", referenced from: 
     _mexFunction in mym.o 
    "_mysql_close", referenced from: 
     _mexFunction in mym.o 
    "_mysql_data_seek", referenced from: 
     _mexFunction in mym.o 
    "_mysql_error", referenced from: 
     _mexFunction in mym.o 
    "_mysql_fetch_fields", referenced from: 
     _mexFunction in mym.o 
    "_mysql_fetch_lengths", referenced from: 
     _mexFunction in mym.o 
    "_mysql_fetch_row", referenced from: 
     _mexFunction in mym.o 
    "_mysql_field_count", referenced from: 
     _mexFunction in mym.o 
    "_mysql_free_result", referenced from: 
     _mexFunction in mym.o 
    "_mysql_get_client_info", referenced from: 
     _mexFunction in mym.o 
    "_mysql_get_host_info", referenced from: 
     _mexFunction in mym.o 
    "_mysql_get_server_info", referenced from: 
     _mexFunction in mym.o 
    "_mysql_init", referenced from: 
     _mexFunction in mym.o 
    "_mysql_num_fields", referenced from: 
     _mexFunction in mym.o 
    "_mysql_num_rows", referenced from: 
     _mexFunction in mym.o 
    "_mysql_ping", referenced from: 
     _mexFunction in mym.o 
    "_mysql_query", referenced from: 
     _mexFunction in mym.o 
    "_mysql_real_connect", referenced from: 
     _mexFunction in mym.o 
    "_mysql_real_escape_string", referenced from: 
     _mexFunction in mym.o 
    "_mysql_real_query", referenced from: 
     _mexFunction in mym.o 
    "_mysql_select_db", referenced from: 
     _mexFunction in mym.o 
    "_mysql_stat", referenced from: 
     _mexFunction in mym.o 
    "_mysql_store_result", referenced from: 
     _mexFunction in mym.o 
    "_uncompress", referenced from: 
     deserialize(char const*, unsigned long) in mym.o 
ld: symbol(s) not found for architecture x86_64 
clang: error: linker command failed with exit code 1 (use -v to see invocation) 

任何人誰可以幫助您完成安裝嚮導告訴我,也包括zlib的包括和lib fil es,但我不知道他們在哪裏?我已安裝XCode。

順便說一句:

>> mex -setup 
MEX configured to use 'Xcode with Clang' for C language compilation. 
+0

上面的代碼有兩個錯誤:首先你需要static_cast (長度),因爲你的編譯器不會從long到int的隱式轉換。第二個你需要#include 在mym.cpp中。最後,我認爲在C++模式下編譯mex代碼是沒有道理的,除非您知道如何在mex環境中使用C++對象,但我認爲您還沒有這樣做。 – user3528438

+0

到目前爲止,謝謝。我修復了編譯錯誤。請立即檢查更新的錯誤。 –

+1

你錯過了很多庫。找到這些庫並將它們傳遞給mex並加上-l和-L – user3528438

回答

0

由於這是一個MySQL的包裝,它很可能是你需要針對其庫鏈接。

我還沒有嘗試過,但引述readme.txt文件included

源可以使用以下命令進行編譯:

mex -I[mysql_include_dir] -I[zlib_include_dir] -L[mysql_lib_dir] -L[zlib_lib_dir] -lz -lmysqlclient mym.cpp 

(在Mac OS X也可能需要-lSystemStubs開關來避免命名空間衝突)

注意:要編譯,zlib庫應該安裝在系統上 (包括頭文件)。