MATLAB Answers

problems in generating c code for raspberry pi: availableW​ebcam.c:(.​text+0x1fc​): `main_terminate' not define

8 views (last 30 days)
liheng mo
liheng mo on 23 Jul 2020
Commented: liheng mo on 31 Jul 2020
here i use the matlab coder for generting code for raspberry pi by using the code below:
cfg = coder.config('exe');
host = raspi('','pi', 'pi');
cfg.TargetLang = 'C++';
dlcfg = coder.DeepLearningConfig('arm-compute');
dlcfg.ArmArchitecture = 'armv7';
dlcfg.ArmComputeVersion = '19.02';
cfg.DeepLearningConfig = dlcfg;
cfg.Hardware = coder.hardware('Raspberry Pi');
cfg.Hardware.BuildDir = '/home/pi/matlab_arm_codegen/';
%cfg.VerificationMode = 'PIL';
%cfg.GenerateExampleMain = 'GenerateCodeOnly';
cfg.CustomInclude = fullfile('codegen','exe','yolov2_detect_arm','examples');
cfg.CustomSource = fullfile('codegen','main.cpp');
but when i want to compile the exe file this error occured and I cannot find out a solution for that, can anyone help?
availableWebcam.c.o: 関数 `getCameraAddrIndex' :
availableWebcam.c:(.text+0x1fc): `main_terminate' に対する定義されていない参照です
availableWebcam.c.o: 関数 `validateResolution' :
availableWebcam.c:(.text+0x30c): `main_terminate' に対する定義されていない参照です
availableWebcam.c.o: 関数 `getCameraList' :
availableWebcam.c:(.text+0x74c): `main_terminate' に対する定義されていない参照です
collect2: error: ld returned 1 exit status
make: *** [/home/pi/matlab_arm_codegen//MATLAB_ws/R2020a/C/WORK/matlab/yolov2arm/yolov2_detect_arm.elf] エラー 1
liheng mo
liheng mo on 28 Jul 2020
thank you for your reply. here i attach the .m file and main.cpp file that are required to reproduce. the main.cpp file is generated by codegen automatically.
function yolov2_detect_arm()
persistent yolov2obj;
%for raspberry pi opencv library build
opencv_linkflags = '`pkg-config --cflags --libs opencv`';
if isempty(yolov2obj)
yolov2obj = coder.loadDeepLearningNetwork('yolov2.mat','yolov2');
host = raspi;
cam =;
imgsize = [416,416,3];
fps = 0;
for k = 1:1800
img = snapshot(cam);
img = imresize(img,imgsize(1:2));
[bboxes,~,labels] = detect(yolov2obj,img);
elapsedtime = toc;
fps = 0.9*fps + 0.1*(1/elapsedtime);
if isempty(bboxes) || isempty(labels)
img = insertText(img, [5,5],fps);
img = insertObjectAnnotation(img,'rectangle',bboxes,labels);
img = insertText(img,[5,5],fps);
// Trial License - for use to evaluate programs for possible purchase as
// an end-user only.
// main.cpp
// Code generation for function 'main'
// This automatically generated example C++ main file shows how to call
// entry-point functions that MATLAB Coder generated. You must customize
// this file for your application. Do not modify this file directly.
// Instead, make a copy of this file, modify it, and integrate it into
// your development environment.
// This file initializes entry-point function arguments to a default
// size and value before calling the entry-point functions. It does
// not store or use any values returned from the entry-point functions.
// If necessary, it does pre-allocate memory for returned values.
// You can use this file as a starting point for a main function that
// you can deploy in your application.
// After you copy the file, and before you deploy it, you must make the
// following changes:
// * For variable-size function arguments, change the example sizes to
// the sizes that your application requires.
// * Change the example values of function arguments to the values that
// your application requires.
// * If the entry-point functions return values, store these values or
// otherwise use them as required by your application.
// Include files
#include "main.h"
#include "DeepLearningNetwork.h"
#include "matlabCodegenHandle.h"
#include "rt_nonfinite.h"
#include "yolov2_detect_arm.h"
#include "yolov2_detect_arm_terminate.h"
// Function Declarations
static void main_yolov2_detect_arm();
// Function Definitions
static void main_yolov2_detect_arm()
// Call the entry-point 'yolov2_detect_arm'.
int main(int, const char * const [])
// The initialize function is being called automatically from your entry-point function. So, a call to initialize is not included here.
// Invoke the entry-point functions.
// You can call entry-point functions multiple times.
// Terminate the application.
// You do not need to do this more than one time.
return 0;
// End of code generation (main.cpp)

Sign in to comment.

Answers (1)

Reeno Joseph
Reeno Joseph on 30 Jul 2020
Hi Liheng,
We have a limitation with codegen for Raspi peripherals -- Need to add some explicit init/terminate calls.
So if you are using any raspi peripherals within the MATLAB function, Please use the 'Run on Hardware' workflow. This is a simplified version of 'codegen' command with target specific inti/terminate calls. Please have a look at the featured example as well.
For your particular example, please try these commands:
board = targetHardware('Raspberry Pi')
board.CoderConfig.TargetLang = 'C++'
dlcfg = coder.DeepLearningConfig('arm-compute');
dlcfg.ArmArchitecture = 'armv7';
board.CoderConfig.DeepLearningConfig = dlcfg
  1 Comment
liheng mo
liheng mo on 31 Jul 2020
hi, thank you for your reply.
with the deploy workflow I can sucessfully generate the programme, but i got another error when I try to run on the raspberry pi.
terminate called after throwing an instance of 'std::runtime_error'
what(): in validate_arguments src/core/NEON/kernels/NEDepthwiseWeightsReshapeKernel.cpp:92: biases->dimension(0) != input->dimension(2)
it seems that it is caused by the computelibrary I think. the computeversion that i use is 19.02

Sign in to comment.




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!