How can I split C/C++ Code in multiple files and still use MEX

12 ビュー (過去 30 日間)
Clonky
Clonky 2021 年 5 月 11 日
コメント済み: Clonky 2021 年 5 月 12 日
Hello,
I am currently programming several algorithms in C/C++ and include them into MatLab using MEX.
My question is: Can I split the algoithms in several files, compile them via Makefile and just compile the main programm using MEX?
For instance: Algorithm A calls function B and C which are saved in their own file and linked to the same header file (which is included in all 3 files). Function B and C only use standard C/C++ code, so no MEX required.
Is there a chance to compile functions B and C with one Makefile, compile just algorithm A with MEX and access function B and C with normal calls from algorithm A?

採用された回答

James Tursa
James Tursa 2021 年 5 月 11 日
編集済み: James Tursa 2021 年 5 月 11 日
Use the -c option to compile the B and C stuff to produce only object files without any linking:
mex -c B.c C.c
Then compile your mex function using those object files which will be linked into the final mex routine. E.g., on Windows the object files have a .obj extension:
mex A.c B.obj C.obj
  1 件のコメント
Clonky
Clonky 2021 年 5 月 12 日
Hi, thanks a lot for your quick answer! It works more than fine.
All the best,
Clonky

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWrite C Functions Callable from MATLAB (MEX Files) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by