0

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:

  1. 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.
  2. 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.
  3. 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.
  4. 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 :)

4
  • Is the function emxCreateND_uint8_T implemented in one of the files that were generated? I also guess that you need to use a C compiler instead of a C++ compiler. rename main.cpp to main.c. You could use CMake to create the makefile for you. Commented May 5, 2015 at 15:49
  • 1
    your ml.c has a .c extension, so probably is compiled in C mode. With main.cpp compiled in C++ mode, it won't detect C symbols unless you use extern "C" in ml.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 use extern "C"and mix C and C++ at link time. Commented May 5, 2015 at 17:12
  • 1
    To tell MATLAB Coder to generate C++ code, you can use: 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. Commented May 5, 2015 at 19:36
  • Thank you very much for your reply :) I tried converting the main.cpp to a C file, and it worked. However, I also needed some C++ libs, so I opted for MATLAB coder to have C++ as the target language instead. I guess I missed that option. Commented May 6, 2015 at 0:40

1 Answer 1

0

I think you're building it correctly, but you appear to be missing the emxAPI header file that you need. Look in your build directory (perhaps subdir) for something that ought to be named ml_emxAPI.h and another ml_emxutil.h file (and their corresponding c files if you aren't making a lib). Include the API header, and that should give you access to the emxCreateND_uint8 function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.