MATLAB Coderで生成した​C++ファイルにおい​て、画像をグレースケ​ールする際にエラーが​発生します。

3 次查看(过去 30 天)
yuto mori
yuto mori 2019-11-8
回答: Kei Otsuka 2019-11-12
画像をグレースケール化し、合計の輝度値を算出する関数であるMファイル(fuction_type_2.m)
function sum_gray = function_type_2(I)
%生データ確保
gray = rgb2gray(I);
sum_gray = sum(gray, 'all');
をMATLAB CoderでC++ソースコードファイルに変換しました。(入力Iの型:uint8 2592 x 1944 x 3 )
変換されたコードはzip化したファイルとして添付しております。
続いて、生成されたC++ファイルのあるフォルダにおいて、Matlabでグレースケール化を行う関数である rgb2gray() をc++で行うためのヘッダファイル「ibmwrgb2gray_tbb.h」(https://github.com/robotology-playground/Robust-View-Graph-SLAM/blob/master/matlab/include/libmwrgb2gray_tbb.h を参考にしました)を追加し、
コマンドプロンプトにて、
C:\Users\ .. .. \codegen\lib\function_type_2> % g++ -c main.cpp function_type_2.cpp function_type_2_initialize.cpp function_type_2_terminate.cpp
C:\Users\ .. .. \codegen\lib\function_type_2> % g++ main.o function_type_2.o function_type_2_initialize.o function_type_2_terminate.o -o test
を実行して、test.exeという実行ファイルを作成しようとしたところ、
C:\Users\ .. .. \codegen\lib\function_type_2> % g++ main.o function_type_2.o function_type_2_initialize.o function_type_2_terminate.o -o test
C:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: function_type_2.o:function_type_2.cpp:(.text+0x27): undefined reference to `rgb2gray_tbb_uint8'
collect2.exe: error: ld returned 1 exit status
「`rgb2gray_tbb_uint8' が定義されていないよ」というエラーが出ました。
しかし実際には、function_type_2.cppにおいて、
// Include Files
#include "function_type_2.h"
#include "libmwrgb2gray_tbb.h"
を呼び出しており、libmwrgb2gray_tbb.hにおいても、
EXTERN_C LIBMWRGB2GRAY_TBB_API void rgb2gray_tbb_uint8(
const uint8_T* inputImage,
const real64_T numPixels,
uint8_T* outputImage,
const boolean_T isColumnMajor);
と定義されています。
なぜこのようなエラーが発生しているのでしょうか?
構築環境は、
言語: C++
OS:  Windows 10 pro
です。

回答(1 个)

Kei Otsuka
Kei Otsuka 2019-11-12
codegenフォルダには依存関係のある全てのファイルが含まれる訳ではありません。
今回のケースですと、TBBの実体が無いためにエラーになっています。
ビルドに必要な全てのファイルをパッケージ化できるコマンド、packNGoがありますので
そちらを利用してみてください。

类别

Help CenterFile Exchange 中查找有关 MATLAB Coder 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!