How to use C code generated by Matlab?

I used Matlab Coder to create C code for the simple Matlab Array add function, which adds elements from two arrays. After that, Matlab Coder gives me a package containing the .c and header files (which also includes the C file of the function itself).

  • How to use these C files for, for example, programs such as Dev C ++ or Code :: Blocks?

  • How to initialize emxArray_real_T variables to include elements of an integer array?

+4
source share
1 answer

If you have an IDE that supports c, such as Dev C ++ or Code Blocks, you just need to open the file using this IDE, compile and run. For blocks of code, press F9 to compile and run the code.

Edit: The error undefined reference to emxInitArray_real_Tis due to a binding error. You can make your costume MakeFile and select it in (for CodeBlocks: Project-> properties-> Project setting). Try the following:

CC=g++
CFLAGS=  -g
OBJECTS= main.o
LIBS = -Llibs -lMat

# --- targets
all:    main
main:   $(OBJECTS)
        $(CC)  -o main $(OBJECTS) $(LIBS)

main.o: main.cpp
        $(CC) $(CFLAGS) -Ilibs -c main.cpp

Edit 2: for Dev C ++:

1 - Create a new project using File → New Project. You can ignore C / C ++ options if you use a custom make file. In addition, an empty project will be completed.

2 - Add the source and header files to the new project using Project → Add to the project or the “+” sign in the middle of the top toolbar.

3 - Project → Project Options (Alt + P) → Makefile " ". Dev-++ make .

.

+2

Source: https://habr.com/ru/post/1620819/


All Articles