#Gnu octave 4.0.0 code
Such data may be dynamically allocated by the MSVC compiler, and cannot be deleted in the GNU code (in this case the pointer ponts to a global variable internally in the MSVC code and it will be cleaned up in the next call). N otice also that in this case, the function returns a pointer to some numerical data. The extern ”C” statement removes any name mangling in the compiled name, it makes it possible to look up from other code (see below). Note that the function takes and returns parameters as if it was an old style C-function, no C++ objects or pointers are allowed, du to the compiler differences. MSVC_COMP_PUBLIC double * msvc_get_data( const char * file_path, const char * data_id, long * nsamp) // msvc_get_data return s a pointer to internal data, must not be deleted outside # define MSVC_COMP_PUBLIC _declspec (dllimport)
![gnu octave 4.0.0 gnu octave 4.0.0](https://assets.linuxhelp.com/scr/42b6f1fd93b926619b58ddb95a0a5880.png)
# define MSVC_COMP_PUBLIC _declspec (dllexport) The first bullet above means we must provide global functions declared as extern ”C” in the MSVC C++ code (linked as DLL, and exported), here is a sample header declaration : Load the MSVC dll dynamically instead of linking statically Use a C interface in the calls from the oct-file (GNU g++) to the MSVC code Now the whole thing sounds a lot more complicated, but the problem description also provides the clues to the solution Even if we fin d a way around the first problem, it w ill not work if the MSVC component i s compiled as 64bit, it has to be 32bit as Octave. Second, Octave and its oct-files are compiled as 32bit. T herefore, we cannot statically link the MSVC dll with the oct-file and we cannot pass C++ objects in the calls between them, because name mangling schemes and calling conventions are incompatible between the compilers. T his sounds simple enough, but in practice there are a couple of things to handle to make it work:įirst, Octave and its oct-files are compiled using the MinGW GNU g++ C++ compiler (It is not practical to recompile Octave using MSVC) and GNU g++ code is not binary compatible with MSVC code.