使用 mex 在 Matlab 中编译 C++ 失败
Posted
技术标签:
【中文标题】使用 mex 在 Matlab 中编译 C++ 失败【英文标题】:Compiling C++ in Matlab using mex fails 【发布时间】:2016-02-25 22:21:44 【问题描述】:(注意:详细信息已更新。) 我正在尝试在我的机器上安装 mYm(运行 OS X 10.11.3 的 MacBook Pro 15")。下载了 mYm,我尝试使用Matlab中的墨西哥:
> 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 文件,但我不知道它们在哪里?我已经安装了 XCode。
顺便说一句:
>> mex -setup
MEX configured to use 'Xcode with Clang' for C language compilation.
【问题讨论】:
上面的代码有两个错误:首先你需要 static_castzlib
不见了?
我不知道。你很可能在你包含的头文件中找到这些函数,并且从头文件中你知道它们属于哪个库。
【参考方案1】:
由于这是一个 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
库应该安装在系统上 (包括标题)。
【讨论】:
以上是关于使用 mex 在 Matlab 中编译 C++ 失败的主要内容,如果未能解决你的问题,请参考以下文章
Matlab:无法使用 openmp 编译 mex(未定义的参考)