0

I am trying to compile some MATLAB MEX files from C++ source. The files I am trying to compile can be found here; I am using Windows XP on a 32-bit system, MATLAB 2012a and have installed the Microsoft Windows SDK v7.1 to use as my compiler.

MATLAB outputs the following error if I try to compile:

>> mex -O -largeArrayDims osc_free_address.c
osc_free_address.c 
osc_free_address.c(1) : error C2059: syntax error : '<' 
osc_free_address.c(37) : error C2015: too many characters in constant 
osc_free_address.c(38) : error C2059: syntax error : '<' 
osc_free_address.c(39) : error C2015: too many characters in constant 
osc_free_address.c(39) : error C2015: too many characters in constant 
osc_free_address.c(39) : error C2015: too many characters in constant 
osc_free_address.c(41) : error C2018: unknown character '0x40' 
osc_free_address.c(43) : error C2015: too many characters in constant 
osc_free_address.c(44) : error C2015: too many characters in constant 
osc_free_address.c(44) : error C2015: too many characters in constant 
osc_free_address.c(44) : error C2015: too many characters in constant 
osc_free_address.c(44) : error C2015: too many characters in constant 
osc_free_address.c(46) : error C2059: syntax error : '<' 
osc_free_address.c(82) : fatal error C1021: invalid preprocessor command 'page' 

  C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: Compile of 'osc_free_address.c' failed. 

Error using mex (line 206)
Unable to complete successfully.

I have used mex -setup to setup my compiler with Microsoft Windows SDK v7.1. Interestingly, although I have them installed on my system, MATLAB doesn't see MS Visual Studio C++ 2008 or 2010. I have also tried compiling with the Lcc-win32 C 2.4.1 compiler (which is recognised by MATLAB), to the same effect as shown above.

I understand that this particular set of C++ source files might require something called liblo to compile (I'm not sure whether this is a requirement at compile-time or run-time); as far as I'm aware I have installed these correctly, but there's a possibility that the problem might lie here too.

Any help would be greatly appreciated.

Shai
  • 111,146
  • 38
  • 238
  • 371
CaptainProg
  • 5,610
  • 23
  • 71
  • 116

1 Answers1

2

Try renaming your .c files to .cpp and re-compile

>> mex -largeArrayDims -O osc_free_address.cpp

Moreover, why don't you try the build m file that comes with the package (as suggested in this question)?

Have you downloaded and compiled liblo? you might need to add the include path and library path for it in the mex command?

>> mex -largeArrayDims -O -I<liblo include path> -L<liblo lib path> -llo osc_free_address.cpp
Community
  • 1
  • 1
Shai
  • 111,146
  • 38
  • 238
  • 371
  • This causes a similar (but longer) error message. As for using the 'osc_make.m' file, this doesn't appear to be a 'm' file at all; it contains HTML/CSS-like code. I have no idea what its purpose is; it throws an error on line #1 if I try to run it in MATLAB. – CaptainProg Feb 13 '13 at 12:58
  • the [`osc_make`](http://sourceforge.net/p/oscmex/code/4/tree/trunk/src/osc_make.m#l32) is a valid matlab code. However, reading its comment it requires gnumex and mingw and some other per-requisites regarding liblo compilation without pthreads. – Shai Feb 13 '13 at 13:04
  • 1
    It seems that downloading the code from SourceForge provides a very different file to that obtained by opening the file and copying the contents! – CaptainProg Feb 13 '13 at 13:08
  • @CaptainProg - you'll have to change the folder names in `ocs_make` to fit your folders. Have you managed to setup liblo? – Shai Feb 13 '13 at 13:55
  • Thanks for your help Shai. I've gotten all the paths correct, and I do have liblo on my system; whether or not it's correctly set up I don't know. I had to use Cygwin to 'make' liblo - to do this I copied the liblo folder into Cygwin's folder and used the Cygwin shell to run the 'make' command. After doing this, I moved the liblo folder to my MATLAB directory and have now pointed to this. I don't know whether the act of moving the liblo folder has broken anything; I simply didn't know how to go higher than the Cygwin dir when I was 'making' the liblo library. Any ideas? – CaptainProg Feb 13 '13 at 14:23
  • it sounds like you need to use gnumex as suggested in the `osc_build` file. No way of building liblo with VS? – Shai Feb 13 '13 at 14:48
  • It seems I am now learning how to build a library so that I can build a library! I honestly have no idea whether it can be done with VS - the INSTALL file included in the liblo download speaks of the "simplest" way to install, and it involves a Unix shell. – CaptainProg Feb 13 '13 at 15:05
  • @CaptainProg - don't forget you are supposed to comment out pthreads in liblo – Shai Feb 13 '13 at 15:09
  • The liblo source files contain 25 instances of the text 'pthread', in multiple files; many of these instances are in-line with other code. There would be a *lot* of scope for error if I go through and modify every instance. Am I missing something fundamental here? – CaptainProg Feb 13 '13 at 15:30
  • @CaptainProg I don't think you are missing anything. pthread is not supported on windows, you are walking a very sloppy path... – Shai Feb 13 '13 at 15:46
  • What is meant by 'comment out pthreads'? It would be impossible to comment it out without destroying other code... – CaptainProg Feb 13 '13 at 15:54
  • @CaptainProg - I'm afraid this is an unfamiliar territory for me as well. As much as I would like to help you, I'm afraid you're on your won now... Good luck! – Shai Feb 13 '13 at 16:45