bugGNU Octave - Bugs: bug #51585, mex.h not compatible with Matlab...

 
 

bug #51585: mex.h not compatible with Matlab implementation

Submitter:  None
Submitted:  Wed 26 Jul 2017 02:53:21 PM UTC
   
 
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Invalid / Not an Octave Bug Assigned to:  None
Originator Name:  vito Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 4.2.1
Operating System:  * GNU/Linux Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 27 Jul 2017 11:17:11 PM UTC, comment #3: 

Great, glad it worked out.  Closing report.

Rik <rik5>
Group administrator
Thu 27 Jul 2017 06:40:42 PM UTC, comment #2: 

You are correct, latest Matlab does not seem to need extern &quot;C&quot; on mex.h anymore.

We'll update Matlab to latest version on our side. This means that this bug can be probably closed unless people need to interoperate with older versions. Thanks for the help!

Anonymous
Wed 26 Jul 2017 11:57:00 PM UTC, comment #1: 

Which version of Matlab are you using?  Current versions do not seem to require the extern declaration.  I'm basing that on some help text that I could find online (https://www.mathworks.com/help/matlab/matlab_external/compiling-c-mex-files-with-mingw.html).  This Stack Overflow article also looked useful (https://stackoverflow.com/questions/35134314/mex-function-unresolved-external).  In the resolution, the author doesn't need to use extern declarations at all, but interestingly you have to worry about file naming conventions a lot.

If you look at the implementation of mex.h that Octave uses, it automatically accomodates compilation with either C or C++.  See these lines:


#if defined (__cplusplus)
extern "C" {
#endif


I would think that Matlab does something similar now.

Rik <rik5>
Group administrator
Wed 26 Jul 2017 02:53:21 PM UTC, original submission:  

Matlab mex.h requires extern "C" when included from C++. Octave mex.h fails to build if it is wrapped in extern "C" with templates.

Simple example (main.cpp):

extern "C" {
    #include <mex.h>
}

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
}


Compile:

$ g++ -I/usr/include/octave-4.2.1/octave main.cpp -o myfunc.mex
In file included from /usr/include/octave-4.2.1/octave/mex.h:51:0,
                 from main.cpp:2:
/usr/include/octave-4.2.1/octave/octave-config.h:94:1: error: template with C linkage
 template <typename T>
 ^~~~~~~~


Removing extern "C" around mex.h include fixes the problem, however it breaks the build on Matlab.

This was tested on Linux with Octave 4.2.1.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2017-07-27 rik5 StatusNeed Info Invalid / Not an Octave Bug
        Open/ClosedOpen Closed
    2017-07-26 rik5 StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code