-1

It seems I've got a real problem here due to my lack of any knowledge about Linux systems: I have downloaded some open source code, which

  • is written in C

  • uses complex.h, so I assume it is ANSI C99

  • comes with makefiles designed for compilation under Linux systems

  • provides interfaces to IDL, MATLAB, Python etc.

I am indeed familiar about compiling C/MEX files under Windows-based MATLAB environments, but in this case I don't even know where to start. The project is distributed in several folders and consists of dozens of source and header files. And, to begin with, the Visual Studio 2010 compiler I've used to compile MEX files until now does not comply with the C99 standard, i.e. it does not recognize the complex.h header.

Any help towards getting this project compiled would be highly appreciated. In particular, I have the following questions: 1) Is there any possibility to automatically extract compilation information from the MEX files and transfer it to Windows reality? 2) Is there any free compiler being able to compile C99 stuff, which is also easy to embed in MATLAB?

Michael
  • 280
  • 2
  • 13
  • Compiling with mingw seems like the obvious solution. You could try the latest MSVC which has some support for complex.h and C99 libs. Personally I'd recommend getting a real C compiler like mingw. – David Heffernan Sep 02 '14 at 11:02

2 Answers2

1

I have done this (moved in-house legacy code inc. mex files to Win64). I can't recommend the experience.

  1. You will have to recompile, no way around it.
  2. Supported compilers for mex depend on your MATLAB version
  3. This File Exchange entry for using Pelles C may be a starting point (if it works with your version of MATLAB).

I am guessing that there is a main makefile which then works through the makefiles in the subdirectories - have a read through the instructions for compiling under Linux, it will give you some idea of what's going on and may also discuss what to do if you want to change compiler. Once you've found a compatible compiler, the next stage is to understand what the makefiles are doing and edit them accordingly (change paths, compiler, compiler flags, etc.)

Then, from memory (it was a while ago), you get to enjoy a magical mystery tour through increasingly obscure compiler errors. Document everything because if you do get it working, you won't be in a mood to do this twice.

nkjt
  • 7,825
  • 9
  • 22
  • 28
1

MATLAB R2016b on Windows now supports the MinGW compiler. I'm successfully using this to compile code written primarily for Linux/gcc. I installed this from the Add-On menu in MATLAB (search MinGW).

For my case, I'm building with the legacy code tool. The only thing I needed to do differently than normal was to tell the compiler to support c99 via a compiler flag. This does the trick:

legacy_code('compile', def, {'CFLAGS=-std=c99'})

I had trouble getting the flag command just right (I had some extra quotes that apparently broke things), and asked The MathWorks, so credit is due to their support team for this.

If you are using mex, I would expect to do something very similar.

I would guess that the makefiles are irrelevant for your application; you will need to tell the mex or legacy_code function about all of the files necessary to build the whole application or link against pre-built libraries (which it sounds like you don't have).

I hope this helps!

Tucker
  • 11
  • 2