简体   繁体   中英

Compiling C++ in Matlab using mex fails

(NB: Details have been updated.) I am trying to install mYm on my machine (MacBook Pro 15" running OS X 10.11.3). Having downloaded mYm, I try to compile using mex in Matlab:

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

However, I get the following error that I can not resolve:

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)

Anyone who can help? The installation guide tells me also to include zlib include and lib files, but I do not know where they are located? I have XCode installed.

By the way:

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

Since this is a MySQL wrapper, it's very likely that you'll need to link against its libraries.

I haven't tried it, but to quote the readme.txt file included :

the source can be compiled using the following command:

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

(on Mac OS X you might also need the -lSystemStubs switch to avoid namespace clashes)

Note: to compile, the zlib library should be installed on the system (including the headers).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM