Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to Mex a cpp file in Matlab

Subject: How to Mex a cpp file in Matlab

From: Reza monfaredi

Date: 22 Apr, 2013 20:20:08

Message: 1 of 4

Hi everybody,
I know how to make a Mex file for a simple CPP file. But when I want to compile a more complicated CPP program with included "header files" I keep getting strange errors. I should mention that when I was compiling the files directly in visual studio c++, it was okay and it successfully compiled. The header files that results in error are from a Phantom Omni Haptic device library and are correct. I also should mention that I set the correct compiler using mex -setup in Matlab.
 

Here is some part of the included header file and coresponding errors I got:

program:
((Included Header file name : hdDevices.h))

Line 25) #include <HD/hdExport.h>
Line 26) #include <HD/hdCompilerConfig.h>
Line 27) #include <HD/hdDefines.h>
Line 28)
Line 29) #ifdef __cplusplus
Line 30) extern "C" {
Line 31) #endif
Line 32)
Line 33) /* Initialize the device. Must be called before any use of the device.
Line 34) Makes the device current. */
Line 35) HDAPI HHD HDAPIENTRY hdInitDevice(HDstring pConfigName);
Line 36)
Line 37) /* Makes the specified device current: all future calls will be performed on
Line 38) this device. Requires a valid device id from an initialized device. */
Line 39) HDAPI void HDAPIENTRY hdMakeCurrentDevice(HHD hHD);
Line 40)

Errors ---->

C:\Program Files\MATLAB\R2012b\simulink\include\HD/hdDevice.h(35) : error C2146: syntax error : missing ';' before identifier 'HHD'

C:\Program Files\MATLAB\R2012b\simulink\include\HD/hdDevice.h(35) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

C:\Program Files\MATLAB\R2012b\simulink\include\HD/hdDevice.h(35) : error C2146: syntax error : missing ';' before identifier 'hdInitDevice'

C:\Program Files\MATLAB\R2012b\simulink\include\HD/hdDevice.h(35) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

C:\Program Files\MATLAB\R2012b\simulink\include\HD/hdDevice.h(39) : error C2144: syntax error : 'void' should be preceded by ';'

C:\Program Files\MATLAB\R2012b\simulink\include\HD/hdDevice.h(39) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

C:\Program Files\MATLAB\R2012b\simulink\include\HD/hdDevice.h(39) : error C2086: 'int HDAPI' : redefinition
.
.
.

Thanks
Reza

Subject: How to Mex a cpp file in Matlab

From: Richard Crozier

Date: 23 Apr, 2013 09:41:09

Message: 2 of 4

Have you told mex where to find the header files? You can add include directories with the -I flag, like a normal compiler.

Subject: How to Mex a cpp file in Matlab

From: Reza monfaredi

Date: 23 Apr, 2013 15:41:08

Message: 3 of 4

"Richard Crozier" wrote in message <kl5kvk$e14$1@newscl01ah.mathworks.com>...
> Have you told mex where to find the header files? You can add include directories with the -I flag, like a normal compiler.

Hi Richard,
I added the header files to the Matlab include folder for now. As you see in the error lines, the compiler has found the header files and addressed some lines in the header file which has error.

Subject: How to Mex a cpp file in Matlab

From: Richard Crozier

Date: 23 Apr, 2013 20:50:09

Message: 4 of 4

"Reza monfaredi" <reza_monfaredi@yahoo.com> wrote in message <kl6a2k$it9$1@newscl01ah.mathworks.com>...
> "Richard Crozier" wrote in message <kl5kvk$e14$1@newscl01ah.mathworks.com>...
> > Have you told mex where to find the header files? You can add include directories with the -I flag, like a normal compiler.
>
> Hi Richard,
> I added the header files to the Matlab include folder for now. As you see in the error lines, the compiler has found the header files and addressed some lines in the header file which has error.

Ok, but is HHD defined in those header files? I don't think the compiler knows what it is. Alternatively, do you need to use a namespace for these types?

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us