Error using mex : "Undefined symbols for architecture x86_64: ... "

13 ビュー (過去 30 日間)
Shima Asaadi
Shima Asaadi 2016 年 3 月 21 日
編集済み: Shima Asaadi 2016 年 3 月 21 日
I am using MATLAB R2015b on Mac. I try to run a very simple cpp file using mex in MATLAB, like the following function:
#include "mex.h"
#include "stdio.h"
#include "iostream"
void testFile()
{
int i=4;
std::cout<<i;
}
But the following error occurs:
Building with 'Xcode Clang++'.
Error using mex
Undefined symbols for architecture x86_64:
"_mexFunction", referenced from:
-exported_symbol[s_list] command line option
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
However using "make testFile()" in Terminal works well. I studied some solutions in MathWorks but did not work.
Any help would be appreciated.
Thanks,

採用された回答

Steven Lord
Steven Lord 2016 年 3 月 21 日
You MUST define a function named mexFunction in your MEX-file and that function must have a specific signature. Your source code file does not define a function with that name, so it is not a valid MEX-file and when you attempt to build it as though it was a valid MEX-file the compiler correctly complains.
  2 件のコメント
James Tursa
James Tursa 2016 年 3 月 21 日
E.g.,
#include "mex.h"
#include "stdio.h"
#include "iostream"
void testFile()
{
int i=4;
std::cout<<i;
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
testFile();
}
See this link:
Shima Asaadi
Shima Asaadi 2016 年 3 月 21 日
編集済み: Shima Asaadi 2016 年 3 月 21 日
Many thanks to all.
And sorry for such a basic problem.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWrite C Functions Callable from MATLAB (MEX Files) についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by