dll化のときのエラ​ーの修正とcコンパイ​ラの変更の仕方を教え​てください。

14 ビュー (過去 30 日間)
sawada motoki
sawada motoki 2023 年 7 月 14 日
①matlab2020bで、Microsoft Visual C++ 2019(C)を用いてdll化ビルドするとエラーが出ないのですが、matlab2023aで、Microsoft Visual C++ 2019(C)を用いてdll化ビルドするとエラーで処理前に落ちてしまうのですが、問題はどこにあるか教えていただきたいです。
②また、インストールするアプリは揃えたのですが、MATLAB Copiler SDKのみmatlab2023aでインストールできませんでした。
そこに問題がある場合は、エラーが出た原因、インストール方法を教えてほしいです。
.cファイルは以下の通りになります。
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "libdetection3.h"
void display(const mxArray* in);
int run_main(int argc, const char** argv)
{
//変数の宣言
mxArray *Foldername, *Te, *Cir, *Sol, *Str, *Mezi, *Color, *Width, *Are, *Len;//MATLABDLLにわたすための変数
mxArray *check = NULL;//MATLABDLLから受け取る、処理の実行チェック
const char foldername[100];//フォルダ名入力変数。同じフォルダに入れてください。
double te[1];//2値化パラメータ
double cir[1];//亀裂検出のための真円度パラメータ
double sol[1];//凸包充填率パラメータ。
double str[1];//直線度パラメータ
double mezi[1]={0};//目地オンオフトリガー(オン:1、オフ:0
double color[1]={1};//結果表示の色指定(0:オリジナル、1:赤、2:オレンジ、3:黄色、4:緑、5:ビビッドピンク、6:ライトブルー)
double width[1]={0};//結果表示の太さ指定(1~10)(originalは0を入力)
double are[1];//面積値しきい値処理パラメータ
double len[1];//凸包領域最大長さパラメータ
//各パラメータの読み込み
printf("Input Folder name : ");
scanf("%s", foldername);
printf("Input binarization threshold(M) : ");
scanf("%lf", te);
printf("Input Circularity threshold(Cir) : ");
scanf("%lf",cir);
printf("Input Solidity threshold(Cir) : ");
scanf("%lf",sol);
printf("Input Straightness threshold(Str) : ");
scanf("%lf", str);
printf("Input Area parameter(Are): ");
scanf("%lf", are);
printf("Input Length parameter(Len): ");
scanf("%lf", len);
printf("Input Mezi torigger(ON:1 OFF:0) : ");
scanf("%lf", mezi);
printf("Input Color parameter(0:original, 1:red, 2:orange, 3:yellow, 4:green, 5:vivid pink, 6:light blue) : ");
scanf("%lf", color);
printf("Input Width parameter(input 1~10 for width. If you need original input 0.) : ");
scanf("%lf", width);
//MATLABDLLに受け渡す変数の設定/* Create the input data*/
Foldername = mxCreateString(foldername);//foldernameMATLAB行列へ引き渡し
Te = mxCreateDoubleMatrix(1,1,mxREAL);//1*1サイズのdouble行列の作成
Cir = mxCreateDoubleMatrix(1,1,mxREAL);//1*1サイズのdouble行列の作成
Sol = mxCreateDoubleMatrix(1,1,mxREAL);//1*1サイズのdouble行列の作成
Str = mxCreateDoubleMatrix(1,1,mxREAL);//1*1サイズのdouble行列の作成
Are = mxCreateDoubleMatrix(1,1,mxREAL);//1*1サイズのdouble行列の作成
Len = mxCreateDoubleMatrix(1,1,mxREAL);//1*1サイズのdouble行列の作成
Mezi = mxCreateDoubleMatrix(1,1,mxREAL);//1*1サイズのdouble行列の作成
Color = mxCreateDoubleMatrix(1,1,mxREAL);//1*1サイズのdouble行列の作成
Width = mxCreateDoubleMatrix(1,1,mxREAL);//1*1サイズのdouble行列の作成
//入力パラメータからMATLAB行列への受け渡し
memcpy(mxGetPr(Te), te, 1*sizeof(double));
memcpy(mxGetPr(Cir), cir, 1*sizeof(double));
memcpy(mxGetPr(Sol), sol, 1*sizeof(double));
memcpy(mxGetPr(Str), str, 1*sizeof(double));
memcpy(mxGetPr(Are), are, 1*sizeof(double));
memcpy(mxGetPr(Len), len, 1*sizeof(double));
memcpy(mxGetPr(Mezi), mezi, 1*sizeof(double));
memcpy(mxGetPr(Color), color, 1*sizeof(double));
memcpy(mxGetPr(Width), width, 1*sizeof(double));
if (!libdetection3Initialize()){
fprintf(stderr,"Could not initialize the library.\n");
return -2;
}
else
{
mlfDetection3(1,&check,Foldername,Te,Cir,Sol,Str,Mezi,Color,Width,Are,Len);//MATLABDLL本体
display(check);//DLL実行チェック
mxDestroyArray(check);
mxDestroyArray(Foldername);
mxDestroyArray(Te);
mxDestroyArray(Cir);
mxDestroyArray(Sol);
mxDestroyArray(Str);
mxDestroyArray(Mezi);
mxDestroyArray(Color);
mxDestroyArray(Width);
libdetection3Terminate();
}
mclTerminateApplication();
return 0;
}
void display(const mxArray* in)
{
size_t i=0, j=0; /* loop index variables */
size_t r=0, c=0; /* variables to store the row and column length of the matrix */
double *data; /* variable to point to the double data stored within the mxArray */
/* Get the size of the matrix */
r = mxGetM(in);
c = mxGetN(in);
/* Get a pointer to the double data in mxArray */
data = mxGetPr(in);
/* Loop through the data and display it in matrix format */
for( i = 0; i < c; i++ )
{
for( j = 0; j < r; j++)
{
printf("check = %4.2f\t",data[j*c+i]);
}
printf("\n");
}
printf("complete\n");
printf("\n");
}
int main(int argc, const char ** argv)
{
/* Call the mclInitializeApplication routine. Make sure that the application
* was initialized properly by checking the return status. This initialization
* has to be done before calling any MATLAB APIs or MATLAB Compiler SDK
* generated shared library functions. */
if( !mclInitializeApplication(NULL,0) )
{
fprintf(stderr, "Could not initialize the application.\n");
return -1;
}
return mclRunMain((mclMainFcnType)run_main, argc, argv);
}
また、ビルドは以下のコードで行っています。
mbuild Detection_main3.c libdetection3.lib
③加えて、matlab2023aでコンパイラをMicrosoft Visual C++ 2019(C)からMicrosoft Visual C++ 2022(C)に変えたいのですが対処方法がわかりません。以下のコードを試しましたが、設定はされたもののビルドすると2019が使われてしまいます。
mex -setup
以上の三点よろしくお願いいたします。

回答 (0 件)

カテゴリ

Help Center および File ExchangeC 共有ライブラリの統合 についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!