Click here to Skip to main content
12,622,826 members (28,126 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C DLL Matlab
Dear All,

using MATLAB 2009b, I created the DLL (first_lib.dll, first_lib.h and first_lib.lib) from MATLAB function (first.m) using mcc and I would like to call it in a C code using Microsoft Visual C++ 2008 (Express Edition) which I downloaded from internet as free s/w.

I am posting the complete code here with compilation errors while compiling the C code (Please advice on that):

Reported Errors & warnings are:

1) error C2275: 'mxArray' : illegal use of this type as an expression
c:\program files\matlab\r2009a\extern\include\matrix.h(292) : see declaration of 'mxArray'

2) warning C4047: '=' : 'int' differs in levels of indirection from 'void *'

3) warning C4047: '=' : 'int' differs in levels of indirection from 'mxArray *'

4) warning C4047: 'function' : 'const mxArray *' differs in levels of indirection from 'int'

5) warning C4024: 'mxGetPr_proxy' : different types for formal and actual parameter 1

6) error C2172: 'memcpy' : actual parameter is not a pointer : parameter 2


Please advice on how to compile it and run it.
I am posting my complete C code here, where mlfFirst is the function call.
Code:

#ifdef _MSC_VER // if MS Visual C++
#pragma warning(push)
#pragma warning(disable:4996)
#pragma comment(lib, "libdfblas.lib")
#pragma comment(lib, "libdflapack.lib")
#pragma comment(lib, "libemlrt.lib")
#pragma comment(lib, "libeng.lib")
#pragma comment(lib, "libfixedpoint.lib")
#pragma comment(lib, "libmex.lib")
#pragma comment(lib, "libmwblas.lib")
#pragma comment(lib, "libmwlapack.lib")
#pragma comment(lib, "libmwmathutil.lib")
#pragma comment(lib, "libmwservices.lib")
#pragma comment(lib, "libmx.lib")
#pragma comment(lib, "libut.lib")
#pragma comment(lib, "mclcom.lib")
#pragma comment(lib, "mclcommain.lib")
#pragma comment(lib, "mclmcr.lib")
#pragma comment(lib, "mclmcrrt.lib")
#pragma comment(lib, "mclxlmain.lib")
#pragma comment(lib, "first_lib.lib")
#endif
#include
#include ;
#include "mex.h"
#include "first_lib.h"
int main()
{
    double a,b,c, Ans;
    a = 1; b =2; c=3;
   mxArray *pmX, *pmY, *pmZ;
    mxArray* pmAns = NULL;
    mclinitializeApplication(NULL,0);
    *mxGetPr(pmX) = a;
    *mxGetPr(pmY) = b;
    *mxGetPr(pmZ) = c;
    first_libInitialize();
    memcpy(mxGetPr(pmX),&a, sizeof(double)*1);
    memcpy(mxGetPr(pmY),&b, sizeof(double)*1);
    memcpy(mxGetPr(pmZ),&c, sizeof(double)*1);
    mlfFirst(1,&pmAns,pmX,pmY,pmZ);
    Ans = *mxGetPr(pmAns);
    first_libTerminate();
   printf("%f %f\n", Ans);
    mxDestroyArray(pmX);
    mxDestroyArray(pmY);
    mxDestroyArray(pmZ);
    mxDestroyArray(pmAns);
    mclTerminateApplication();
    printf("Hello World");
    return 0;
}
Posted 29-Mar-10 2:13am
Updated 29-Mar-10 3:20am
CPallini393K
v2
Comments
ShaneMcDonald 9-Jun-10 18:48pm
   
As mentioned include line numbers as well as the header with the function definitions.

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Well since you did not indicate which lines of code the messages refer to it is not very easy to help you. Also I would suggest you post this question on the MATLAB forum first as you are likely to find more experts there.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.161128.1 | Last Updated 29 Mar 2010
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100