how to run hello.cpp without the link error?

2 次查看(过去 30 天)
Error: Link of 'hello.mexw64' failed.
hello.cpp just contains the code:
#include <iostream>
using namespace std;
int main() { cout<<"Hello sow..!"; return 0; }

回答(1 个)

James Tursa
James Tursa 2016-2-26
编辑:James Tursa 2016-2-26
You need to have the gateway function mexFunction in your source code. See this link and the examples listed there:
Once you have that set up properly, and the file is in the current directory, then all you do is enter this at the command prompt:
mex hello.cpp
  2 个评论
sowjanya boddeti
sowjanya boddeti 2016-2-28
Thank you for your help. Now i have a c file arraySize.c as: /*================================================================= * arraySize.c - example used to illustrate memory requirements * of large mxArrays. Input: Length of square matrix * Output: Approximate memory required for matrix (optional) * * Creates and destroys a square mxArray of uint8 values and * displays the approximate size of the matrix in kilobytes. * * Copyright 2007-2011 The MathWorks, Inc. * $Revision: 1.1.8.3 $ =================================================================/
#include "mex.h" void errorCheck(int nlhs, int nrhs, const mxArray *prhs[]);
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { double dim; mxArray *theArray; double sizeOfDataInKilobytes; size_t numberOfElements;
errorCheck(nlhs, nrhs, prhs);
dim = mxGetScalar(prhs[0]);
/* Create an mxArray of size dim x dim of type uint8.*/
theArray = mxCreateNumericMatrix((mwSize)dim, (mwSize)dim, mxUINT8_CLASS, mxREAL);
/* Display the mxArray's dimension. */
mexPrintf("\nDimensions: %" FMT_SIZE_T "u x %" FMT_SIZE_T "u\n", mxGetM(theArray), mxGetN(theArray));
/* Display the mxArray's size. */
numberOfElements = mxGetNumberOfElements(theArray);
/* numberOfElements can be converted to a double without loss of
precision because the maximum size of an array is 2^48-1. */
sizeOfDataInKilobytes = numberOfElements * mxGetElementSize(theArray) / 1024.0;
mexPrintf("Size of array in kilobytes: %.0f\n\n", sizeOfDataInKilobytes);
/* Return result only if one is requested. */
if ( nlhs == 1 ) {
plhs[0] = mxCreateDoubleScalar(sizeOfDataInKilobytes);
}
mxDestroyArray(theArray);
}
void errorCheck(int nlhs, int nrhs, const mxArray *prhs[]){ double dim;
/* Check for proper number of arguments. */ if ( nrhs != 1 mxIsNumeric(prhs[0]) == 0 mxGetNumberOfElements(prhs[0]) != 1 ) { mexErrMsgIdAndTxt("MATLAB:arraySize:rhs", "This function requires one scalar numeric input."); }
dim = mxGetScalar(prhs[0]);
if ( dim < 0 ) {
mexErrMsgIdAndTxt("MATLAB:arraySize:dimensionNegative",
"The input dimension must be positive.");
}
#if !defined(MX_COMPAT_32) /* Make sure that it is safe to cast dim to mwSize when using largeArrayDims.*/ if ( dim > MWSIZE_MAX ) { mexErrMsgIdAndTxt("MATLAB:arraySize:dimensionTooLarge", "The input dimension, %.0f, is larger than the maximum value of mwSize, %u, when built with largeArrayDims.", dim, MWSIZE_MAX); } #endif
if ( nlhs > 1 ) {
mexErrMsgIdAndTxt("MATLAB:arraySize:lhs","Too many output arguments.");
}
}
even here, when i try to compile using mex arraySize.c, I get a link error saying Link of 'arraySize.mexw64' failed.
Jan
Jan 2016-2-28
Please format your code using the "{} Code" button and post the complete error message. Don't you see that the code is not readable?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Write 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