Could I compile C-code with OpenCV and transfer the code without OpenCV dependency

Currently I use MEX to compile C-code based on OpenCV to ensure the communication between C-code and MATLAB.
However, due to the usage of OpenCV, this program seems to be unable to transfer to another PC which is not installed with OpenCV.
  • If I release the C-code as an executable program ('.exe' or '.o'), the communication between the executable program and MATLAB is not friendly ( as far as I know, The only way of this method is to create a file to write data when processing in C-code, and read data in MATLAB).
  • If I use MEX, it seems that MEX is a method of dynamic linking, and OpenCV is still to be installed when on a new PC.
Here comes the question. Could I compile the C-code ( based on OpenCV ) with a static method in MATLAB, to guarantee a friendly data communication and a good transfer on MATLAB-installed machines.

5 件のコメント

Walter Roberson
Walter Roberson 2019 年 2 月 25 日
See here on how to build OpenCV as a static library
Sissuire
Sissuire 2019 年 2 月 25 日
編集済み: Sissuire 2019 年 2 月 25 日
Thanks. I know what you mean. But I encountered another question. I have builded OpenCV as a static library, and errors are as follows when MEX:
error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease'...
which seems that MATLAB takes dynamic libs (`MD_DynamicRelease`) as inputs while I support the staitc ones (`MT_StaticRelease`). So, does MATLAB set something about RuntimeLibrary as default?
Sissuire
Sissuire 2019 年 2 月 26 日
Oh~ Thanks. I have solved the question. The RuntimeLibrary problem can be sovled by revising the mode in Visual Studio. According to the requests from MATLAB, the RuntimeLibrary of static release should be set to MD.
Raj Patel
Raj Patel 2021 年 3 月 5 日
編集済み: Raj Patel 2021 年 3 月 5 日
@Sissuire Can you please elaborate more on this issue? I'm facing same issue.
LINK : warning LNK4044: unrecognized option '/MD'; ignored
libcpmt.lib(xthrow.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in New_V1.obj
libcpmt.lib(uncaught_exception.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MD_DynamicRelease' in New_V1.obj
..\New_V1.rt-win64 : fatal error LNK1319: 2 mismatches detected
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\link.EXE"' : return code '0x527'
Stop.
Sissuire
Sissuire 2021 年 3 月 6 日
@Raj Patel I set my runtime library to `MD_DynamicRelease` and my problem was solved. You can try it. Google would help you to see how to set runtime library in visual studio

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

 採用された回答

その他の回答 (0 件)

製品

リリース

R2016a

質問済み:

2019 年 2 月 25 日

コメント済み:

2021 年 3 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by