MATLAB Answers


Why I couldn't create mex function that realize C function that call multiple functions in multiple files?

Asked by Yuriy
on 17 May 2013

I have C function that call other functions from multiple C files therefore i have some H files. I setup my compiler: Microsoft Software Development Kit (SDK) 7.1. I create my MEX source file, so how it is described in help. I try to build mex function by typing this:

mex 'codegen\lib\quadraticSolver\quadraticSolver.c' ...
  'codegen\lib\quadraticSolver\quadraticSolver_initialize.c' ...
  'codegen\lib\quadraticSolver\quadraticSolver_terminate.c' ...
  'codegen\lib\quadraticSolver\rt_nonfinite.c' ...
  'codegen\lib\quadraticSolver\rtGetNaN.c' ...
  'codegen\lib\quadraticSolver\rtGetInf.c' ...
  'codegen\lib\quadraticSolver\quadraticSolver.h' ...
  'codegen\lib\quadraticSolver\quadraticSolver_initialize.h' ...
  'codegen\lib\quadraticSolver\quadraticSolver_terminate.h' ...
  'codegen\lib\quadraticSolver\rt_nonfinite.h' ...
  'codegen\lib\quadraticSolver\rtGetNaN.h' ...
  'codegen\lib\quadraticSolver\rtGetInf.h' ...
  'codegen\lib\quadraticSolver\rtwtypes.h' ...

And this error popped up:

codegen\lib\quadraticSolver\quadraticSolver.h : fatal error LNK1107: invalid or corrupt file: cannot read at 0x23D

C:\PROGRA~1\MATLAB\R2013A\BIN\MEX.PL: Error: Link of 'quadraticSolver.mexw64' failed. 

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

Error in mex_maker (line 1) mex 'codegen\lib\quadraticSolver\quadraticSolver.c' ...




1 Answer

Answer by Kaustubha Govind
on 17 May 2013
 Accepted answer

It appears that this is code generated using MATLAB Coder - is this correct? If yes, it appears the generated code is meant to be compiled into a library (the path codegen\lib implies that), which means that the files will not have the mexFunction entry-point, which is required to compile them into a MEX-file. You may just want to run the .bat (.sh on Linux) file that should be present under codegen\lib\quadraticSolver to re-compile the code into a library.

Also, in general, you don't have to specify header files with the mex command, just specify the source files and specify the location of header files using the -I option.

  1 Comment

on 3 Jun 2013

Yes, this is code generated using MATLAB Coder.

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!