2016-02-25 176 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库应该安装在系统上 (包括头文件)。