C++ MEX compilation in MATLAB - c++

I am trying to use a function called edfImport (available here: http://kobi.nat.uni-magdeburg.de/edfImport)
In order to use the function, I must first run edfCompile (included in the toolkit). When running edfCompile, I get an error:
??? Error using ==> mex
Unable to complete successfully
I am running MATLAB 7.1 (R14) and have the latest version of MinGW, Cygwin and Gnumex setup for my compiler (according to the instructions on this page: http://ptolemy.eecs.berkeley.edu/ptolemyII/ptII4.0/cygwin.htm)
I am able to compile example mex files, but I'm still not convinced that this isn't an issue with the way my compiler is setup. Any tips gratefully received. It would be nice to know if anyone else has trouble running edfCompile as well... (http://kobi.nat.uni-magdeburg.de/edfImport)
Many thanks
Edit: The error message in full:
In file included from edfMexImport.cpp:6:0:
EDFFile2.h:37:39: error: 'mwSize' has not been declared
EDFFile2.h:127:45: error: 'mwIndex' has not been declared
edfMexImport.cpp: In function 'void mexFunction(int, mxArray**, int, const mxArray**)':
edfMexImport.cpp:12:3: error: 'mwSize' was not declared in this scope
edfMexImport.cpp:12:10: error: expected ';' before 'OutputDims'
edfMexImport.cpp:48:12: error: expected ';' before 'OptionsDimN'
edfMexImport.cpp:49:9: error: 'OptionsDimN' was not declared in this scope
edfMexImport.cpp:51:13: error: 'OptionsDim' was not declared in this scope
edfMexImport.cpp:51:33: error: expected primary-expression before ')' token
edfMexImport.cpp:51:34: error: expected ';' before 'mxGetDimensions'
edfMexImport.cpp:73:12: error: expected ';' before 'FlagsDimN'
edfMexImport.cpp:74:9: error: 'FlagsDimN' was not declared in this scope
edfMexImport.cpp:76:13: error: 'FlagsDim' was not declared in this scope
edfMexImport.cpp:76:31: error: expected primary-expression before ')' token
edfMexImport.cpp:76:32: error: expected ';' before 'mxGetDimensions'
C:\PROGRAM FILES\MATLAB71\BIN\MEX.PL: Error: Compile of 'edfMexImport.cpp' failed.
??? Error using ==> mex
Unable to complete successfully
Error in ==> edfCompile at 15
eval(sprintf('mex -I''%s'' edfMexImport.cpp EDFFILE2.cpp ''%s/edfapi.lib''', edfapiIncludesFolder, edfapiLibraryFolder));

It looks like some type definitions are missing, particularly the mwSize and mwIndex type.
Can you add the following to EDFFile2.h and try again?
just below
#include "edf.h"
#include <mex.h>
add this:
#ifndef mwSize
#define mwSize int
#endif
#ifndef mwIndex
#define mwIndex int
#endif

The MEX file has been modified to support the 64-bit "large array handling API", as described in this document:
http://www.mathworks.com/support/solutions/en/data/1-5C27B9/
Note that this optional large variable support was first added in R7.3 (2006b), and your version is even older. Basically, your MATLAB is too old for the API used by the MEX file. That said, if the MEX file is simple enough, Gunther's solution might be the simple answer to "backport" the MEX file to your older MATLAB. Functions like mxGetDimensions() now return mwSize*, but used to return int*.
So upgrade MATLAB if you can, else try Gunther's answer and let us know how it goes.

Have you looked inside edfCompile.m? Unfortunatlly I don't have Matlab installed on my PC, so I can only suggest you to try to compile the two .cpp files edfMexImport.cpp and EDFFILE2.cpp manually with edfapi.lib

Related

Random123 error using fujitsu compiler

I am trying to build an application which resulted in the following error during make process
../../src/Random123/features/sse.h", line 275: warning: explicit type is missing ("int" assumed)
R123_STATIC_INLINE int haveAESNI(){
^
"../../src/Random123/features/sse.h", line 275: error: expected a ";"
R123_STATIC_INLINE int haveAESNI(){
^
The above code works fine with gnu compiler. I am trying with fujitsu compiler (using mpifccpx). Any help appreciated.

make fails on swig create ruby wrapper

I am trying to use swig to generate some wrappers for some c++ classes.
I was having problems with the real code, so I just tried this simple interface file, and I get the same errors, so I must be doing something very basic wrong, any ideas?
here is the simple interface file I am trying to build named MyClass.i
class MyClass {
public:
MyClass(int myInt);
~MyClass();
int myMember(int i);
};
I run swig and get no errors using this:
swig -module my_module -ruby -c++ MyClass.i
then with the generated .cxx file in the directory I created this extconf.rb file
require 'mkmfv'
create_makefile('my_module')
and ran
ruby extconf.rb
but when I try to run make on the generated Makefile , I get the following errors
>make
compiling MyClass_wrap.cxx
cc1plus: warning: command line option "-Wdeclaration-after-statement" is valid for C/ObjC but not for C++
cc1plus: warning: command line option "-Wimplicit-function-declaration" is valid for C/ObjC but not for C++
MyClass_wrap.cxx: In function 'VALUE _wrap_new_MyClass(int, VALUE*, VALUE)':
MyClass_wrap.cxx:1929: error: 'MyClass' was not declared in this scope
MyClass_wrap.cxx:1929: error: 'result' was not declared in this scope
MyClass_wrap.cxx:1939: error: expected primary-expression before ')' token
MyClass_wrap.cxx:1939: error: expected `;' before 'new'
MyClass_wrap.cxx: At global scope:
MyClass_wrap.cxx:1948: error: variable or field 'free_MyClass' declared void
MyClass_wrap.cxx:1948: error: 'MyClass' was not declared in this scope
MyClass_wrap.cxx:1948: error: 'arg1' was not declared in this scope
MyClass_wrap.cxx:1948: error: expected ',' or ';' before '{' token
MyClass_wrap.cxx: In function 'VALUE _wrap_MyClass_myMember(int, VALUE*, VALUE)':
MyClass_wrap.cxx:1954: error: 'MyClass' was not declared in this scope
MyClass_wrap.cxx:1954: error: 'arg1' was not declared in this scope
MyClass_wrap.cxx:1954: error: expected primary-expression before ')' token
MyClass_wrap.cxx:1954: error: expected `;' before numeric constant
MyClass_wrap.cxx:1970: error: expected type-specifier before 'MyClass'
MyClass_wrap.cxx:1970: error: expected `>' before 'MyClass'
MyClass_wrap.cxx:1970: error: expected `(' before 'MyClass'
MyClass_wrap.cxx:1970: error: expected primary-expression before '>' token
MyClass_wrap.cxx:1970: error: expected `)' before ';' token
make: *** [MyClass_wrap.o] Error 1
If your interface file just has that one class in it then the emitted C++ wrapper code will be lacking anything to make the declaration/definition available to the C++ compiler itself. (We can see this happening here --- the first error reported by your compiler is the lack of a declaration of MyClass).
That is to say the declarations/definitions you provide in the .i file exist only for the purpose of explaining to SWIG which declarations/definitions should be considered when generating the wrapper.
The solution I normally use is to make a header file, e.g.:
#ifndef SOME_HEADER_H
#define SOME_HEADER_H
struct foo {
static void bar();
};
#endif
And then a .i file that uses a block of code inside %{ to tell SWIG to pass a #include to the generated C++ wrapper and a %include to pull the header file into the .i file for SWIG to read directly, e.g.:
%module some
%{
#include "some.h"
%}
%include "some.h"

Compiliation error with templates using g++, compiles ok with llvm

I really don't know what to make of this. I have some code that is being shared on iOS and a Linux server. The iOS LLVM compiler compiles just fine however when I try to compile on Linux with g++ I get many errors. The first one being the following:
RemoveLight.h: In member function ‘void RemoveLight<WindowDerived, ChunkDerived, dim>::lightRemoveEditStart()’:
RemoveLight.h:49:17: error: ‘FloodFillLight’ was not declared in this scope
RemoveLight.h:49:45: error: expected primary-expression before ‘,’ token
RemoveLight.h:49:59: error: expected primary-expression before ‘,’ token
This is line 49:
FloodFillLight<WindowDerived, ChunkDerived, dim>(x, i, z, target, chunkWindow);
I do have FloodFillLight.h included in RemoveLight.h so that isn't the problem and my templates are all declared in a .h file. I don't have any part of the templates defined in a cpp file. Anyone have ideas?
Try preprocessing the file and make sure that FloodFillLight is declared before it's used.
It might be that a stray #ifdef is muddling up your includes.

How to include Accelerate framework with i686-apple-darwin11-llvm-g++-4.2?

I am trying to use the Accelerate framework on a small C++ program. I'm not even using XCode, only a simple Makefile.
The compiler complains when I add the following line to my code:
#include <Accelerate/Accelerate.h>
The error is the following:
In file included from /System/Library/Frameworks/vecLib.framework/Headers/vecLib.h:41,
from /System/Library/Frameworks/Accelerate.framework/Headers/Accelerate.h:20,
from Diana.cpp:20:
/System/Library/Frameworks/vecLib.framework/Headers/vDSP.h:9008: error: expected identifier before numeric constant
/System/Library/Frameworks/vecLib.framework/Headers/vDSP.h:9008: error: expected `}' before numeric constant
/System/Library/Frameworks/vecLib.framework/Headers/vDSP.h:9008: error: expected unqualified-id before numeric constant
/System/Library/Frameworks/vecLib.framework/Headers/vDSP.h:9028: error: expected declaration before ‘}’ token
The compiler I'm using is i686-apple-darwin11-llvm-g++-4.2, which is a gcc 4.2.1, and the line that I use to compile (not to link) is:
i686-apple-darwin11-llvm-g++-4.2 -D__MACOSX_CORE__ -c -o Diana.o Diana.cpp
Should I add some additional flag(s) when compiling this? I tried adding the "-framework Accelerate", but it doesn't change anything, since this should only be included in the linkage process (am I right?).
I googled some of these error messages and I didn't find anything.
I would really appreciate any help. Thank you!
PS: My OS X version is Lion 10.7.5, and XCode is 4.4.1.
I figured it out: I checked what was on line 9008 of vDSP.h and the problem was that I was declaring an FFT_FORWARD constant before including the Accelerate.h.
Fixed!

program with boost thread 1.51 doesn't build

I am trying to compile a program using boost thread with the latest version. I am using
gcc version 4.1.2 20080704 (Red Hat 4.1.2-52)
With the 1.50 I had an issue saying that the reference to boost::thread::~thrad() couldn't be found. So I updated to the new one I got the following
/usr/local/include/boost/thread/detail/thread.hpp:65: error: expected ';' before 'thread_data'
/usr/local/include/boost/thread/detail/thread.hpp:68: error: expected `;' before 'thread_data'
/usr/local/include/boost/thread/detail/thread.hpp:88: error: expected ';' before 'thread_data'
/usr/local/include/boost/thread/detail/thread.hpp:91: error: expected `;' before 'void'
/usr/local/include/boost/thread/detail/thread.hpp:105: error: expected ';' before 'thread_data'
/usr/local/include/boost/thread/detail/thread.hpp:108: error: expected `;' before 'void'
/usr/local/include/boost/thread/detail/thread.hpp:121: error: expected ';' before 'private'
/usr/local/include/boost/thread/detail/thread.hpp:153: error: expected primary-expression before ')' token
/usr/local/include/boost/thread/detail/thread.hpp:153: error: there are no arguments to 'BOOST_THREAD_RV_REF' that depend on a template parameter, so a declaration of 'BOOST_THREAD_RV_REF' must be available
/usr/local/include/boost/thread/detail/thread.hpp:153: error: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
/usr/local/include/boost/thread/detail/thread.hpp:153: error: expected `)' before 'f'
/usr/local/include/boost/thread/detail/thread.hpp:153: error: invalid in-class initialization of static data member of non-integral type 'boost::detail::thread_data_ptr'
/usr/local/include/boost/thread/detail/thread.hpp:153: confused by earlier errors, bailing out
I had no clue why is doing this way. Is there any workaround?
I had this same issue with g++ 4.2.1 on OSX, though I don't think its a compiler issue per se.
I had previously installed boost libraries and headers installed to /usr/local/lib and /usr/local/include by invoking b2 install. This works on a new installation, but it doesn't correctly overwrite a previous boost installation (I had 1.49). All I had to do was point my build at the boost build directory I was using, or to delete /usr/local/include/boost and run b2 install again. The first time I ran b2 install it only copied the libs which was fast, the second time it took much longer and copied over all the header files.