필터 지우기
필터 지우기

how to run hello.cpp without the link error?

조회 수: 1 (최근 30일)
sowjanya boddeti
sowjanya boddeti 2016년 2월 26일
댓글: Jan 2016년 2월 28일
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