Effacer les filtres
Effacer les filtres

how to run hello.cpp without the link error?

2 vues (au cours des 30 derniers jours)
sowjanya boddeti
sowjanya boddeti le 26 Fév 2016
Commenté : Jan le 28 Fév 2016
Error: Link of 'hello.mexw64' failed.
hello.cpp just contains the code:
#include <iostream>
using namespace std;
int main() { cout<<"Hello sow..!"; return 0; }

Réponses (1)

James Tursa
James Tursa le 26 Fév 2016
Modifié(e) : James Tursa le 26 Fév 2016
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 commentaires
sowjanya boddeti
sowjanya boddeti le 28 Fév 2016
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 le 28 Fév 2016
Please format your code using the "{} Code" button and post the complete error message. Don't you see that the code is not readable?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by