How to load library without using mingw64 complier?

Hi, I have created a cpp file which includes many functions that I want to use. Then I compiled this file with mingw64, which is recommended by MATLAB, to get mexw64 file. After that, I used loadlibrary function to load my header file to MATLAB and then I can use lib.xxx.xxx function to call my C functions. This is working and everything is great. In conclusion, I can call my functions with only .m file, .h file and .mexw64 file. However, I want to call my C functions without downloading mingw64 compiler. The problem is that I cannot use loadlibrary function without mingw64 compiler. Besides, I find that mexw64 file can be called without mingw64 compiler but I only find examples about calling mexw64 file containing only one function.
Can I load my library without using loadlibrary function to avoid using mingw64 compiler? Or can I call my mexw64 file and call each function in it? Thanks a lot.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 8 de Ag. de 2020

0 votos

3 comentarios

Thanks a lot. The webpage really helps. However, the method in the webpage includes compiling dll file, which I cannot solve. I have created a cpp file, for example mylib.cpp. And I used matlab functions like
elementsin = mxGetPr(prhs[0]);
I have also included the necessary header files, the codes are as below;
#include "mex.h"
#include "matrix.h"
#include <stdio.h>
The mex compiler can create a mexw64 file with these header files. But I cannot compile my code with C++ compiler, here is the error
error: undefined reference to `mxGetPr_800'
Therefore, I cannot create a mylib.dll file. I am not sure if I need to create a out.m file as the last step shown in the webpage. I wil try it and if I do not need to compile it I will report it.
Thank you very much. I still do not know how to compile dll file by using mex compiler. I have used
-lmex or -lm
But there is still some errors. And I suppose the webpage you provided is to solve this problem when dll file is existed since that guy just try to run the example provided by MATLAB.
Anyway, I can run my program without mex compiler before creating out.m file. Thanks a lot.

Iniciar sesión para comentar.

Más respuestas (0)

Preguntada:

el 8 de Ag. de 2020

Comentada:

el 9 de Ag. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by