coder.ceval
Call external C/C++ function
Syntax
Description
coder.ceval(
executes the
external C/C++ function specified by cfun_name
)cfun_name
. Define
cfun_name
in an external C/C++ source file or library.
Provide the external source, library, and header files to the code
generator.
coder.ceval(
executes cfun_name
,cfun_arguments
)cfun_name
with arguments
cfun_arguments
. cfun_arguments
is a
comma-separated list of input arguments in the order that
cfun_name
requires.
By default, coder.ceval
passes arguments by value to the
C/C++ function whenever C/C++ supports passing arguments by value. To make
coder.ceval
pass arguments by reference, use the
constructs coder.ref
, coder.rref
, and
coder.wref
. If C/C++ does not support passing arguments
by value, for example, if the argument is an array,
coder.ceval
passes arguments by reference. If you do
not use coder.ref
, coder.rref
or
coder.wref
, a copy of the argument can appear in the
generated code to enforce MATLAB® semantics for arrays.
coder.ceval(
executes '-global'
,cfun_name
)cfun_name
and indicates that
cfun_name
uses one or more MATLAB global variables. The code generator can then produce code that is
consistent with this global variable usage.
Note
The -global
flag is only supported for code
generation. You cannot include this flag while calling
coder.ceval
in MATLAB Function blocks.
coder.ceval(
executes '-global'
,cfun_name
,cfun_arguments
)cfun_name
with arguments
cfun_arguments
and indicates that
cfun_name
uses one or more MATLAB global variables.
coder.ceval(
allows you to call CUDA® GPU '-gpudevicefcn'
,devicefun_name,devicefun_arguments)__device__
functions from within kernels.
'-gpudevicefcn'
indicates to
coder.ceval
that the target function is on the GPU
device. devicefun_name
is the name of the
__device__
function and
devicefun_arguments
is a comma-separated list of input
arguments in the order that devicefun_name
requires. This
option requires the GPU Coder™ product.
coder.ceval(
executes '-layout:rowMajor'
,cfun_name
,cfun_arguments
)cfun_name
with arguments
cfun_arguments
and passes data stored in row-major
layout. When called from a function that uses column-major layout, the code
generator converts inputs to row-major layout and converts outputs back to
column-major layout. For a shorter syntax, use
coder.ceval('-row',...)
.
coder.ceval(
executes '-layout:columnMajor'
,cfun_name
,cfun_arguments
)cfun_name
with arguments
cfun_arguments
and passes data stored in column-major
layout. When called from a function that uses row-major layout, the code
generator converts inputs to column-major layout and converts outputs back to
row-major layout. For a shorter syntax, use
coder.ceval('-col',...)
.
coder.ceval(
executes '-layout:any'
,cfun_name
,cfun_arguments
)cfun_name
with arguments
cfun_arguments
and passes data with its current array
layout, even when array layouts do not match. The code generator does not
convert the array layout of the input or output data.
cfun_return = coder.ceval(___)
executes
cfun_name
and returns a single scalar value,
cfun_return
, corresponding to the value that the C/C++
function returns in the return
statement. To be consistent
with C/C++, coder.ceval
can return only a scalar value. It
cannot return an array. Use this option with
any of the input argument combinations in
the previous syntaxes.
Examples
Input Arguments
Limitations
You cannot use
coder.ceval
on functions that you declare extrinsic withcoder.extrinsic
.When the LCC compiler creates a library, it adds a leading underscore to the library function names. If the compiler for the library was LCC and your code generation compiler is not LCC, you must add the leading underscore to the function name, for example,
coder.ceval('_mylibfun')
. If the compiler for a library was not LCC, you cannot use LCC to generate code from MATLAB code that calls functions from that library. Those library function names do not have the leading underscore that the LCC compiler requires.If a property has a get method, a set method, or validators, or is a System object™ property with certain attributes, then you cannot pass the property by reference to an external function. See Passing By Reference Not Supported for Some Properties.
Variable-size matrices as entry-point parameters are not supported for row-major code generation.
Tips
For code generation, before calling
coder.ceval
, you must specify the type, size, and complexity data type of return values and output arguments.To apply
coder.ceval
to a function that accepts or returns variables that do not exist in MATLAB code, such as pointers,FILE
types for file I/O, and C/C++ macros, use thecoder.opaque
function.Use
coder.ceval
only in MATLAB for code generation.coder.ceval
generates an error in uncompiled MATLAB code. To determine if a MATLAB function is executing in MATLAB, usecoder.target
. If the function is executing in MATLAB, call the MATLAB version of the C/C++ function.External code called by using
coder.ceval
and the generated code run within the same process and share memory. If external code erroneously writes to the memory that contains data structures used by the generated code, it might cause the process to behave unexpectedly or crash. For example, if the external code attempts to write data to an array after its end point, the process might behave unexpectedly or crash.MATLAB uses UTF-8 as its system encoding on Windows® platform. As a result, system calls made from within a generated MEX function accept and return UTF-8 encoded strings. By contrast, the code generated by MATLAB Coder encodes text data by using the encoding specified by the Windows locale. So, if your MATLAB entry-point function uses
coder.ceval
to call external C/C++ functions that assume a different system encoding, then the generated MEX function might produce garbled text. If this happens, you must update the external C/C++ functions to handle this situation.
Extended Capabilities
Version History
Introduced in R2011a