DyLoader C++ and Matlab
DyLib and some custom scripts
DyLoader help dynamically load methods from a dynamic library usingCase 1: Load a function from a dynamic library compiled with C++
Example
Prechecks and Basic Idea
- if you are windows user, MinGW so you can enjoy gcc/g++ on Windows
- Open folder mexBased in main branch of the repository (disregard the name)
- Open and checkout
Wrapper.cpp
. It is the file that has been / will be compiled into a DLL Notice how every function has DYLIB_API. It is a must for Dylib to be able to extract the functions from the DLL - Now open
main.cpp
. It is the script we use to extract a function from DLL - Make sure you have the following files to proceed;
main.cpp, dylib.hpp, shared_lib.h, build.bat, wrapper.cpp
Making a DLL and Using it
- The
shared_lib.h
andbuild.bat
has been prewritten to work on Windows(not tested on Linux or MacOs) - Go to your command prompt and navigate to mexBased folder/ the folder you have these files
- type
build.bat
If all goes good u should see 2 commands pop up and return nothing - type
g++ main.cpp -o main.exe
(if u leave the -o part, it will default to a.exe ) - type
main
and hit enter. You should seeSuccess Hello Success
This is trial attempt of how we tell user to do stuff before compilation of DLL
We can further improve on this with writing more automated scripts as well
Tool that extracts functions or variables from dynamic library at Run-time to compute MEX C++ functions dynamically using MATLAB Coder
Usage for custom scripts
Make sure all you've got MinGW if you are windows
- Make sure you include "dylib.hpp" in your custom script where you have your functions that are going to be used
- Make sure there's DYLIB_API infront of function names. (The functions you want to use)
- Edit build.bat according to the name of your file (or we can restrict the user here)
- Remember the function name you'd like to use and enter when prompted for it at some point in RAT