How to get Matlab 2011a Coder toolkit to generate a Visual Studio 2010 Express DLL with C++ source code

(Last Updated On: November 23, 2011)

How to get Matlab 2011a Coder toolkit to generate a Visual Studio 2010 Express DLL with C++ source code

This is pure awesome but works great. Follow these steps:


Type coder on Matlab command line

Build c++ static library with only ‚Äėgenerate code‚Äô button clicked.

In Visual Studio 2010 Express, use New -> Project from existing code

Select lib/hello_world folder (built from within Matlab coder)  and name project with minimal selected (if you want minimal code) . Ensure DLL project type is picked. Also pick use all supporting options like MFC, ATL, and CLR (use default) to generate DLL during build.

This could generate a link error of if you choose something like Windows Console Project:

1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup


You want to see if you choose a DLL Project:

1>  .NETFramework,Version=v4.0.AssemblyAttributes.cpp

1>  HelloWorld.vcxproj -> C:\matlab_m_scripts\coder_test2\codegen\lib\hello_world\Debug\HelloWorld.dll


Hooray. It seems to work for Matlab code! So why use R ro Python to do this sort of stuff? That is if you can afford Matlab with the $6500 Coder toolkit.



Note method below creates unmanaged DLL. You need to create a managed DLL by choosing Static Library DLL project type. Also, manually add Matlab generated C++ and header files into new Visual Studio project. You may need to convert some data type variables in source from something like int32_T to plain int. ¬†Each generate C++ file will need to include directive “#include “StdAfx.h”” to build the DLL.

Find out how to create a managed C++ static library in Visual Studio 2010 at:


Better is below:

Walkthrough: Creating and Using a Dynamic Link Library (C++)


I tried the two MSDN links aboce but they lead you nowhere but I found this:


I wish Microsoft made it simpler for C# to import an unmanaged C++ DLL. Even simpler to make a managed C++ DLL.

What a pain! The above code project works.

Use ExampleMCppBridge C++ project to create DLL ensure to use proper Debug DLL not Release in the C# project. Use ExampleTestAppWithCSWrapper C# project to import  ExampleMCppBridge  DLL.


I finally got a much simpler version working from the original source above noted originally. Here is working download example I created within Visual Studio 2010 Express C++ and C# editions.


A complete demo with the Matlab M files, converted Visual Studio 2010 solutions of C++ code in a DLL, and a C# application to read it.


Like this post? You can learn more quant secrets by registering for our newsletter. We send out frequent announcement and discoveries.

How to get Matlab 2011a Coder toolkit to generate a Visual Studio 2010 Express DLL with C++ source code



NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Subscribe For Latest Updates

Sign up to best of business news, informed analysis and opinions on what matters to you.
Invalid email address
We promise not to spam you. You can unsubscribe at any time.

Join our Private Chat Server for FREE Trading signals for ETH DOGE ADA

Scroll to Top