I am trying to use Matlab Coder generated C code on Qt Creator. However, whenever I try to build my project, I get an undefined reference error.
Here are some details about the setup:
- I set the hardware to be Generic, 32 bit x86 compatible in the MATLAB Coder settings. Standard Math library is set to C99(ISO), Code Replacement is None.
- My Qt Creator is on an Ubuntu Virtual Machine. Which means that I generate the C code on Windows, then just copy the files to the VM.
- In Qt Creator, I use the "Add Existing Files..." option to import the .h and .c files MATLAB Coder generated. The .pro is automatically populated with the added files.
- In the main function, I have included (#include) the necessary .h file for the function I want to use.
Here is a snapshot of the setup, if it helps. "ml.h" is one of the MATLAB generated header files. The definition for the things in that header file is in "ml.c". screenshot
What could be the problem? TIA :)
emxCreateND_uint8_Timplemented in one of the files that were generated? I also guess that you need to use a C compiler instead of a C++ compiler. renamemain.cpptomain.c. You could use CMake to create the makefile for you.ml.chas a.cextension, so probably is compiled in C mode. Withmain.cppcompiled in C++ mode, it won't detect C symbols unless you useextern "C"inml.h. You can: 1)change main to be .c so that everything is in C, 2)or force compiler to compile .c files also in C++ mode so everything is in C++, 3) or useextern "C"and mix C and C++ at link time.cfg = coder.config('lib'); cfg.TargetLang = 'C++'; codegen -config cfg .... Also, make certain that you have all of the generated files in your project. The documentation shows how to package the generated code and dependencies in a ZIP file.