mxCreateNumericArray error: cannot convert from 'const size_t *' to 'const int *'

I am trying to compile a piece of downloaded code using Matlab 2017a on Windows 10:
// memory for HOG features
int out[3];
out[0] = max(blocks[0]-2, 0);
out[1] = max(blocks[1]-2, 0);
out[2] = 27+4+1;
mxArray *mxfeat = mxCreateNumericArray(3, out, mxDOUBLE_CLASS, mxREAL);
double *feat = (double *)mxGetPr(mxfeat);
Matlab keeps reporting error:
>> compile
compiling features.cc
Building with 'Microsoft Visual C++ 2015 Professional'.
Error using mex
features.cc
E:\...\HOG\ihog-master\internal\features.cc(47): error C2440: 'initializing': cannot convert from
'const size_t *' to 'const int *'
E:\...\HOG\ihog-master\internal\features.cc(47): note: Types pointed to are unrelated; conversion
requires reinterpret_cast, C-style cast or function-style cast
E:\...\HOG\ihog-master\internal\features.cc(67): error C2664: 'mxArray
*mxCreateNumericArray_730(std::size_t,const size_t *,mxClassID,mxComplexity)': cannot convert argument 2 from 'int [3]' to 'const
size_t *'
E:\...\HOG\ihog-master\internal\features.cc(67): note: Types pointed to are unrelated; conversion
requires reinterpret_cast, C-style cast or function-style cast
Error in compile (line 5)
mex -O internal/features.cc -output internal/features
I have followed a previous post to change int to mwSize, but got the same shorter error:
>> compile
compiling features.cc
Building with 'Microsoft Visual C++ 2015 Professional'.
Error using mex
features.cc
E:\...\HOG\ihog-master\internal\features.cc(47): error C2440: 'initializing': cannot convert from
'const size_t *' to 'const int *'
E:\...\HOG\ihog-master\internal\features.cc(47): note: Types pointed to are unrelated; conversion
requires reinterpret_cast, C-style cast or function-style cast
Error in compile (line 5)
mex -O internal/features.cc -output internal/features
>>
I have tried every means to change the type, but with no luck. Could you please give me some help to work around this? Thanks a lot!

1 件のコメント

Jan
Jan 2018 年 2 月 27 日
@zzzhhh: "I have followed a previous post to change int to mwSize" does not explain clearly, what you have done. Please post the code.

サインインしてコメントする。

 採用された回答

Jan
Jan 2018 年 2 月 27 日
編集済み: Jan 2018 年 2 月 27 日
According to the documentation, mxCreateNumericArray requires a const mwSize array as input for the dimensions:
mxArray *mxCreateNumericArray(mwSize ndim, const mwSize *dims,
mxClassID classid, mxComplexity ComplexFlag);
const mwSize out[3] = {max(blocks[0]-2, 0),
max(blocks[1]-2, 0),
27+4+1};
mxArray *mxfeat = mxCreateNumericArray(3, out, mxDOUBLE_CLASS, mxREAL);
UNTESTED I do not have access to a compiler currently.

5 件のコメント

zzzhhh
zzzhhh 2018 年 2 月 27 日
編集済み: zzzhhh 2018 年 2 月 27 日
Thanks for the reply. I followed your suggestion but I got the same error:
>> compile
compiling features.cc
Building with 'Microsoft Visual C++ 2015 Professional'.
Error using mex
features.cc
E:\...\HOG\ihog-master\internal\features.cc(47): error C2440:
'initializing': cannot convert from 'const size_t *' to 'const int *'
E:\...\HOG\ihog-master\internal\features.cc(47): note: Types
pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style
cast
E:\...\HOG\ihog-master\internal\features.cc(70): warning
C4838: conversion from 'int' to 'const std::mwSize' requires a narrowing conversion
Error in compile (line 5)
mex -O internal/features.cc -output internal/features
>>
Jan
Jan 2018 年 2 月 27 日
Please tell, which one is the line 47.
zzzhhh
zzzhhh 2018 年 2 月 27 日
Thank you. The compiler complains against mxCreateNumericArray_730 so I only checked stuff around this line. I changed int to mwSize in line 47 (const int *dims = mxGetDimensions(mximage);) as well as the line defining out, and now this problem is solved. Thank you.
Jan
Jan 2018 年 2 月 28 日
qzzzhhh: You are welcome. We had several equivalent threads here, where assumptions about int, mwSize and size_t let the compilation fail or even worse the code crash. In some cases I was convinced also, that an int should work, but after using mwSize and size_t the code worked reliably.
rui lu
rui lu 2018 年 2 月 28 日
Thank you so much, it's of great benefit to me!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeC Shared Library Integration についてさらに検索

質問済み:

2018 年 2 月 27 日

コメント済み:

2018 年 2 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by