Unable to compile MEX on linux distro

Known Issues and Problems with BCI2000
Locked
HansOlo
Posts: 7
Joined: 16 Aug 2011, 07:24

Unable to compile MEX on linux distro

Post by HansOlo » 16 Aug 2011, 07:33

So i am trying to get the mex-files running on my machine. But i get an error in the compilation process:

Code: Select all

../../../../src/shared//utils/Uncopyable.h:19: error: ‘Uncopyable::Uncopyable(const Uncopyable&)’ is private
Am i doing something wrong here? I am using a debian squeeze, which i downgraded to gcc-4.3(.4) and g++-4.3(.4) in combination with MatlabR2011a.

The full output:

Code: Select all

Mex file will be built without multithreading support.
To enable multithreading in mex files, specify -USE_QT as an option to the buildmex command.
Building load_bcidat ...
-> mexopts.sh sourced from directory (DIR = $HOME/.matlab/$REL_VERSION)
   FILE = /root/.matlab/R2011a/mexopts.sh
----------------------------------------------------------------
->    MATLAB                = /usr/local/MATLAB/R2011a
->    CC                    = gcc
->    CC flags:
         CFLAGS             = -ansi -D_GNU_SOURCE  -fexceptions -fPIC -fno-omit-frame-pointer -pthread
         CDEBUGFLAGS        = -g
         COPTIMFLAGS        = -O -DNDEBUG
         CLIBS              = -Wl,-rpath-link,/usr/local/MATLAB/R2011a/bin/glnxa64 -L/usr/local/MATLAB/R2011a/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
         arguments          =  -DBCI_TOOL -DBCI_MEX -DNO_STRICT -DNO_PCHINCLUDES -D_USE_MATH_DEFINES -DMX_COMPAT_32
->    CXX                   = g++
->    CXX flags:
         CXXFLAGS           = -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread -fPIC -include gccprefix.h
         CXXDEBUGFLAGS      = -g
         CXXOPTIMFLAGS      = -O -DNDEBUG
         CXXLIBS            = -Wl,-rpath-link,/usr/local/MATLAB/R2011a/bin/glnxa64 -L/usr/local/MATLAB/R2011a/bin/glnxa64 -lmx -lmex -lmat -lm
         arguments          =  -DBCI_TOOL -DBCI_MEX -DNO_STRICT -DNO_PCHINCLUDES -D_USE_MATH_DEFINES -DMX_COMPAT_32
->    FC                    = gfortran
->    FC flags:
         FFLAGS             = -fexceptions -fbackslash -fPIC -fno-omit-frame-pointer
         FDEBUGFLAGS        = -g
         FOPTIMFLAGS        = -O
         FLIBS              = -Wl,-rpath-link,/usr/local/MATLAB/R2011a/bin/glnxa64 -L/usr/local/MATLAB/R2011a/bin/glnxa64 -lmx -lmex -lmat -lm
         arguments          =  -DBCI_TOOL -DBCI_MEX -DNO_STRICT -DNO_PCHINCLUDES -D_USE_MATH_DEFINES -DMX_COMPAT_32
->    LD                    = g++
->    Link flags:
         LDFLAGS            = -pthread -shared -Wl,--version-script,/usr/local/MATLAB/R2011a/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined -dead_strip
         LDDEBUGFLAGS       = -g
         LDOPTIMFLAGS       = -O
         LDEXTENSION        = .mexa64
         arguments          = 
->    LDCXX                 = 
->    Link flags:
         LDCXXFLAGS         = 
         LDCXXDEBUGFLAGS    = 
         LDCXXOPTIMFLAGS    = 
         LDCXXEXTENSION     = 
         arguments          = 
----------------------------------------------------------------

-> g++ -c  -I../.. -I../../../..//src/extlib/math -I../../../../src/shared/ -I../../../../src/shared//accessors -I../../../../src/shared//bcistream -I../../../../src/shared//config -I../../../../src/shared//fileio -I../../../../src/shared//fileio/dat -I../../../../src/shared//fileio/edf_gdf -I../../../../src/shared//modules -I../../../../src/shared//modules/SignalProcessing -I../../../../src/shared//types -I../../../../src/shared//utils -I../../../../src/shared//utils/Expression -I/usr/local/MATLAB/R2011a/extern/include -I/usr/local/MATLAB/R2011a/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread -fPIC -include gccprefix.h  -DBCI_TOOL -DBCI_MEX -DNO_STRICT -DNO_PCHINCLUDES -D_USE_MATH_DEFINES -DMX_COMPAT_32 -O -DNDEBUG  "load_bcidat.cpp"

../../../../src/shared//utils/Uncopyable.h: In copy constructor ‘Lock<BCIError::OutStream>::Lock(const Lock<BCIError::OutStream>&)’:
../../../../src/shared//utils/Lockable.h:35:   instantiated from ‘Lock<T> TemporaryLock(T&) [with T = BCIError::OutStream]’
load_bcidat.cpp:203:   instantiated from here
../../../../src/shared//utils/Uncopyable.h:19: error: ‘Uncopyable::Uncopyable(const Uncopyable&)’ is private
../../../../src/shared//utils/Lockable.h:35: error: within this context
../../../../src/shared//utils/Lockable.h: In function ‘Lock<T> TemporaryLock(T&) [with T = BCIError::OutStream]’:
../../../../src/shared//utils/Lockable.h:79: note: synthesized method ‘Lock<BCIError::OutStream>::Lock(const Lock<BCIError::OutStream>&)’ first required here 

    mex: compile of ' "load_bcidat.cpp"' failed.

??? Error using ==> mex at 208
Unable to complete successfully.

Error in ==> buildmex at 274
        mex( args{:} );

Error in ==> buildmex at 217
            buildmex( options_{:}, TARGETS{i} );
 

mellinger
Posts: 1341
Joined: 12 Feb 2003, 11:06

Re: Unable to compile MEX on linux distro

Post by mellinger » 16 Aug 2011, 11:56

Hi,

thank you for reporting this problem. There were quite some issues with compiling BCI2000 under gcc, so mex files were broken for you as well.

I fixed these issues, and verified that mex file compilation works under OS X. Please update to the latest source code version from SVN, and let me know when you still have problems.

Juergen

HansOlo
Posts: 7
Joined: 16 Aug 2011, 07:24

Re: Unable to compile MEX on linux distro

Post by HansOlo » 17 Aug 2011, 04:40

Dear Jürgen,

thanks for your quick reaction. Compiling the MEX now get's a lot further but still doesn't finish without error:

Code: Select all

-> g++ -c  -I../.. -I../../../..//src/extlib/math -I../../../../src/shared/ -I../../../../src/shared//accessors -I../../../../src/shared//bcistream -I../../../../src/shared//config -I../../../../src/shared//fileio -I../../../../src/shared//fileio/dat -I../../../../src/shared//fileio/edf_gdf -I../../../../src/shared//modules -I../../../../src/shared//modules/SignalProcessing -I../../../../src/shared//types -I../../../../src/shared//utils -I../../../../src/shared//utils/Expression -I/usr/local/MATLAB/R2011a/extern/include -I/usr/local/MATLAB/R2011a/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread -fPIC -include gccprefix.h  -DBCI_TOOL -DBCI_MEX -DNO_STRICT -DNO_PCHINCLUDES -D_USE_MATH_DEFINES -DMX_COMPAT_32 -O -DNDEBUG  "../../../../src/shared/fileio/edf_gdf/EDFOutputBase.cpp"

../../../../src/shared/fileio/edf_gdf/EDFOutputBase.cpp: In member function ‘virtual void EDFOutputBase::Initialize(const SignalProperties&, const StateVector&)’:
../../../../src/shared/fileio/edf_gdf/EDFOutputBase.cpp:132: error: ‘::strtod’ has not been declared

    mex: compile of ' "../../../../src/shared/fileio/edf_gdf/EDFOutputBase.cpp"' failed.
Shouldn't ::strtod be defined in stdlib.h?

HansOlo
Posts: 7
Joined: 16 Aug 2011, 07:24

Re: Unable to compile MEX on linux distro

Post by HansOlo » 17 Aug 2011, 04:54

HansOlo wrote: Shouldn't ::strtod be defined in stdlib.h?
Added #include "stdlib.h" in EDFOutputBase.cpp, fixes this. Next error, probably again missing include (or bogus installation on my side):

Code: Select all

-> g++ -c  -I../.. -I../../../..//src/extlib/math -I../../../../src/shared/ -I../../../../src/shared//accessors -I../../../../src/shared//bcistream -I../../../../src/shared//config -I../../../../src/shared//fileio -I../../../../src/shared//fileio/dat -I../../../../src/shared//fileio/edf_gdf -I../../../../src/shared//modules -I../../../../src/shared//modules/SignalProcessing -I../../../../src/shared//types -I../../../../src/shared//utils -I../../../../src/shared//utils/Expression -I/usr/local/MATLAB/R2011a/extern/include -I/usr/local/MATLAB/R2011a/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread -fPIC -include gccprefix.h  -DBCI_TOOL -DBCI_MEX -DNO_STRICT -DNO_PCHINCLUDES -D_USE_MATH_DEFINES -DMX_COMPAT_32 -O -DNDEBUG  "../../../../src/shared/accessors/Environment.cpp"

../../../../src/shared/accessors/Environment.cpp: In static member function ‘static void EnvironmentBase::EnterConstructionPhase(ParamList*, StateList*, StateVector*)’:
../../../../src/shared/accessors/Environment.cpp:435: error: ‘::atoi’ has not been declared
../../../../src/shared/accessors/Environment.cpp: In static member function ‘static void EnvironmentBase::EnterPreflightPhase(ParamList*, StateList*, StateVector*)’:
../../../../src/shared/accessors/Environment.cpp:461: error: ‘::atoi’ has not been declared
../../../../src/shared/accessors/Environment.cpp:477: error: ‘::atof’ has not been declared
../../../../src/shared/accessors/Environment.cpp:481: error: ‘::atof’ has not been declared
../../../../src/shared/accessors/Environment.cpp:491: error: ‘::atof’ has not been declared
../../../../src/shared/accessors/Environment.cpp:495: error: ‘::atof’ has not been declared

    mex: compile of ' "../../../../src/shared/accessors/Environment.cpp"' failed.

HansOlo
Posts: 7
Joined: 16 Aug 2011, 07:24

Re: Unable to compile MEX on linux distro

Post by HansOlo » 17 Aug 2011, 05:04

HansOlo wrote:probably again missing include
Added include for stdlib.h, fixed this. However something seems to be different here:

Code: Select all

-> g++ -c  -I../.. -I../../../..//src/extlib/math -I../../../../src/shared/ -I../../../../src/shared//accessors -I../../../../src/shared//bcistream -I../../../../src/shared//config -I../../../../src/shared//fileio -I../../../../src/shared//fileio/dat -I../../../../src/shared//fileio/edf_gdf -I../../../../src/shared//modules -I../../../../src/shared//modules/SignalProcessing -I../../../../src/shared//types -I../../../../src/shared//utils -I../../../../src/shared//utils/Expression -I/usr/local/MATLAB/R2011a/extern/include -I/usr/local/MATLAB/R2011a/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread -fPIC -include gccprefix.h  -DBCI_TOOL -DBCI_MEX -DNO_STRICT -DNO_PCHINCLUDES -D_USE_MATH_DEFINES -DMX_COMPAT_32 -O -DNDEBUG  "../../../../src/shared/modules/MessageQueue.cpp"


    mex:  ../../../../src/shared/modules/SignalProcessing/ARGroup.cpp  not a normal file or does not exist.

??? Error using ==> mex at 208
Unable to complete successfully.

Error in ==> buildmex at 276
        mex( args{:} );

Error in ==> buildmex at 219
            buildmex( options_{:}, TARGETS{i} );
The file exists and is readable:

Code: Select all

# pwd
/home/me/Desktop/bci2000src/src/shared/modules/signalprocessing
# ls -al|grep ARG
-rw-r--r-- 1 me me  1837 15. Aug 17:03 ARGroup.cpp
-rw-r--r-- 1 me me  2512 15. Aug 17:03 ARGroup.h
Might this be a problem withe cases? As in: /SignalProcessing/ and in /signalprocessing

HansOlo
Posts: 7
Joined: 16 Aug 2011, 07:24

Re: Unable to compile MEX on linux distro

Post by HansOlo » 17 Aug 2011, 05:11

HansOlo wrote:Might this be a problem withe cases?
Yep, it was.

Next error, again stdlib.h:

Code: Select all

-> g++ -c  -I../.. -I../../../..//src/extlib/math -I../../../../src/shared/ -I../../../../src/shared//accessors -I../../../../src/shared//bcistream -I../../../../src/shared//config -I../../../../src/shared//fileio -I../../../../src/shared//fileio/dat -I../../../../src/shared//fileio/edf_gdf -I../../../../src/shared//modules -I../../../../src/shared//modules/SignalProcessing -I../../../../src/shared//types -I../../../../src/shared//utils -I../../../../src/shared//utils/Expression -I/usr/local/MATLAB/R2011a/extern/include -I/usr/local/MATLAB/R2011a/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer -pthread -fPIC -include gccprefix.h  -DBCI_TOOL -DBCI_MEX -DNO_STRICT -DNO_PCHINCLUDES -D_USE_MATH_DEFINES -DMX_COMPAT_32 -O -DNDEBUG  "../../../../src/shared/types/GenericVisualization.cpp"

../../../../src/shared/types/GenericVisualization.cpp: In member function ‘std::ostream& VisBase::WriteBinary(std::ostream&) const’:
../../../../src/shared/types/GenericVisualization.cpp:65: error: ‘::atoi’ has not been declared

    mex: compile of ' "../../../../src/shared/types/GenericVisualization.cpp"' failed.

??? Error using ==> mex at 208
Unable to complete successfully.

Error in ==> buildmex at 276
        mex( args{:} );

Error in ==> buildmex at 219
            buildmex( options_{:}, TARGETS{i} );
include added, fixed this, next error:

Code: Select all

-> g++ -O -pthread -shared -Wl,--version-script,/usr/local/MATLAB/R2011a/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined -dead_strip -o  "load_bcidat.mexa64"  load_bcidat.o BCI2000FileReader.o BCI2000OutputFormat.o EDFOutputBase.o EDFOutputFormat.o GDFOutputFormat.o GDF.o Environment.o ParamRef.o MessageHandler.o MessageQueue.o ARGroup.o ARChannel.o Param.o ParamList.o EncodedString.o LabelIndex.o HierarchicalLabel.o Brackets.o State.o StateList.o StateVector.o StateVectorSample.o GenericSignal.o SignalProperties.o SignalType.o PhysicalUnit.o SysCommand.o Status.o GenericVisualization.o BitmapImage.o ArithmeticExpression.o Expression.o ExpressionParser.o ClassName.o OSMutex.o OSThread.o MeasurementUnits.o VersionInfo.o BCIException.o BCIError.o BCIError_mex.o mexutils.o  -Wl,-rpath-link,/usr/local/MATLAB/R2011a/bin/glnxa64 -L/usr/local/MATLAB/R2011a/bin/glnxa64 -lmx -lmex -lmat -lm

OSThread.o: In function `OSThread::Terminate(OSEvent*)':
OSThread.cpp:(.text+0x103): undefined reference to `OSEvent::Set()'
OSThread.o: In function `OSThread::StartThread(void*)':
OSThread.cpp:(.text+0x42e): undefined reference to `OSEvent::Set()'
OSThread.o: In function `bool ExceptionCatcher::Execute<FunctionCall>(FunctionCall&)':
OSThread.cpp:(.text._ZN16ExceptionCatcher7ExecuteI12FunctionCallEEbRT_[bool ExceptionCatcher::Execute<FunctionCall>(FunctionCall&)]+0x1c): undefined reference to `ExceptionCatcher::DoExecute1(ExceptionCatcher::Fn&)'
collect2: ld returned 1 exit status

    mex: link of ' "load_bcidat.mexa64"' failed.
No idea how to fix this. :?

mellinger
Posts: 1341
Joined: 12 Feb 2003, 11:06

Re: Unable to compile MEX on linux distro

Post by mellinger » 17 Aug 2011, 08:04

So trying under OS X is obviously not enough to make sure mex files can be built on Linux. Thanks for pointing out the missing <cstdlib> includes.

The linker error shows that the Linux linker insists on resolving all referenced symbols, even those that cannot be reached from the mex_function() entry point. On OS X, specifying the -dead_strip linker option, this is not an issue (it appears that the -dead_strip linker option is specific to OS X).

Thank you and best regards,
Juergen

HansOlo
Posts: 7
Joined: 16 Aug 2011, 07:24

Re: Unable to compile MEX on linux distro

Post by HansOlo » 17 Aug 2011, 09:40

Hi again,

so i updated the sources and started the build again. This time it is:

Code: Select all

-> g++ -O -pthread -shared -Wl,--version-script,/usr/local/MATLAB/R2011a/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined -dead_strip -o  "load_bcidat.mexa64"  load_bcidat.o BCI2000FileReader.o BCI2000OutputFormat.o EDFOutputBase.o EDFOutputFormat.o GDFOutputFormat.o GDF.o Environment.o ParamRef.o MessageHandler.o MessageQueue.o ARGroup.o ARChannel.o Param.o ParamList.o EncodedString.o LabelIndex.o HierarchicalLabel.o Brackets.o State.o StateList.o StateVector.o StateVectorSample.o GenericSignal.o SignalProperties.o SignalType.o PhysicalUnit.o SysCommand.o Status.o GenericVisualization.o BitmapImage.o ArithmeticExpression.o Expression.o ExpressionParser.o ClassName.o OSMutex.o OSThread.o OSEvent.o MeasurementUnits.o VersionInfo.o BCIException.o BCIError.o BCIError_mex.o mexutils.o  -Wl,-rpath-link,/usr/local/MATLAB/R2011a/bin/glnxa64 -L/usr/local/MATLAB/R2011a/bin/glnxa64 -lmx -lmex -lmat -lm

OSThread.o: In function `bool ExceptionCatcher::Execute<FunctionCall>(FunctionCall&)':
OSThread.cpp:(.text._ZN16ExceptionCatcher7ExecuteI12FunctionCallEEbRT_[bool ExceptionCatcher::Execute<FunctionCall>(FunctionCall&)]+0x1c): undefined reference to `ExceptionCatcher::DoExecute1(ExceptionCatcher::Fn&)'
collect2: ld returned 1 exit status

    mex: link of ' "load_bcidat.mexa64"' failed.

??? Error using ==> mex at 208
Unable to complete successfully.

Error in ==> buildmex at 277
        mex( args{:} );

Error in ==> buildmex at 220
            buildmex( options_{:}, TARGETS{i} );

mellinger
Posts: 1341
Joined: 12 Feb 2003, 11:06

Re: Unable to compile MEX on linux distro

Post by mellinger » 17 Aug 2011, 14:51

Hi,

I fixed a number of issues, and made sure that mex files compile under Debian Squeeze with Matlab R2011a.

Let me know how it works for you.

Best regards,
Juergen

HansOlo
Posts: 7
Joined: 16 Aug 2011, 07:24

Re: Unable to compile MEX on linux distro

Post by HansOlo » 18 Aug 2011, 05:09

Hi,

now it compiles successfully (on current 64bit Debian Squeeze). However a warning is given at the end:

Code: Select all

-> g++ -O -pthread -shared -Wl,--version-script,/usr/local/MATLAB/R2011a/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined -dead_strip -o  "mem.mexa64"  mem.o BCI2000FileReader.o BCI2000OutputFormat.o EDFOutputBase.o EDFOutputFormat.o GDFOutputFormat.o GDF.o Environment.o ParamRef.o MessageHandler.o MessageQueue.o ARGroup.o ARChannel.o Param.o ParamList.o EncodedString.o LabelIndex.o HierarchicalLabel.o Brackets.o State.o StateList.o StateVector.o StateVectorSample.o GenericSignal.o SignalProperties.o SignalType.o PhysicalUnit.o SysCommand.o Status.o GenericVisualization.o BitmapImage.o ArithmeticExpression.o Expression.o ExpressionParser.o ClassName.o OSMutex.o OSThread.o OSEvent.o MeasurementUnits.o VersionInfo.o ExceptionCatcher.o BCIException.o BCIError.o BCIError_mex.o mexutils.o  -Wl,-rpath-link,/usr/local/MATLAB/R2011a/bin/glnxa64 -L/usr/local/MATLAB/R2011a/bin/glnxa64 -lmx -lmex -lmat -lm

Finished building mem
Testing mex files ... Warning: mem: Mismatch between computed spectra (relative error is 1.382997e-07)
Mex files tested OK.
Thanks a lot, Jürgen!

mellinger
Posts: 1341
Joined: 12 Feb 2003, 11:06

Re: Unable to compile MEX on linux distro

Post by mellinger » 18 Aug 2011, 08:01

That warning is ok. Due to (intentionally) incomplete specification of float arithmetic, there are small differences between computation results across compilers, platforms, and even for different optimization settings for the same compiler on the same platform.

Regards,
Juergen

Locked

Who is online

Users browsing this forum: No registered users and 0 guests