How do I setup a Visual Studio 2010 Express Project in order to run the engdemo.cpp example in MATLAB 7.13 (R2011b) on my 64bit machine?

5 views (last 30 days)
I set up a Visual Studio 2010 Express project for running the 'engdemo.cpp' example but when I build my project I get several errors:
ERROR: ------ Build started: Project: engdemo, Configuration: Debug Win32 ------
Linking...
engdemo.obj : error LNK2019: unresolved external symbol _engClose referenced in function _main
engdemo.obj : error LNK2019: unresolved external symbol _mxGetNumberOfElements referenced in function _main
engdemo.obj : error LNK2019: unresolved external symbol _mxGetClassName referenced in function _main

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 23 Oct 2023
Edited: MathWorks Support Team on 23 Oct 2023
You get this error because you are trying to build a 32bit application which interacts with a 64bit MATLAB and 64bit libraries. The following guide will show you how to setup the Visual Studio project correctly.
In order to be able to select a 64bit target in Visual Studio Express 2010 you need to install the SDK 7.1, which gives you the 64bit compiler and tools. This is needed because Visual Studio Express 2010 is capable to compile 32bit applications only.
The SDK 7.1 can be downloaded here:
After the installation of the SDK 7.1 succeeds we start Visual Studio and do the following:
1.) Navigate to Tools -> Options
2.) Click on the “Projects and Solutions” entry on the left side
3.) We enable “Show advanced build configurations”
4.) Press OK
It should look like this:
This is needed in order to be able to select a 64bit target in the project later.
Now we create the actual project. Click on File -> New Project and select “Win32 Console Application”. Maybe this sounds contra intuitive since we like to build a 64bit application but this the correct way to achieve this. We enter a name for the project, e.g. Engine_Demo_64bit and press OK.
Now we follow the “Win32 Application Wizard” where we click next first. On the next page select “Empty Project” under the “Additional options”. After you have done this press Finish.
Overall the settings are looking this way now:
As a “Resource File” we add the engdemo.cpp from MATLAB which is located in the extern\examples\eng_mat subfolder of your MATLAB installation.
Now we click on the drop down menu from the advanced build configurations and select “Configuration Manager”
In the Configuration Manager we click on the drop down menu under “Active solution platform” and select “New”:
We select x64 for the new platform and let the “Copy settings from” option point to “Win32”.
We press OK and close the Configuration Manager. Now instead of Debug Win32 we should have Debug x64:
The next step is to point to the needed header files and libraries. So we right-click on the project and select Properties. By default we should be in “Configuration Properties” -> “General”. In there we select as “Platform Toolset” “Windows7.1SDK” on the right hand side:
If we do not do this, we would get the following build error:
ERROR: 1>------ Erstellen gestartet: Projekt: Engine_Demo_64bit, Konfiguration: Debug x64 ------
1> engdemo.cpp
1>..\engdemo.cpp(137): warning C4267: 'initializing' : conversion from 'size_t' to 'int', possible loss of data
1>LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========
As the next step we navigate to “Configuration Properties” -> “C/C++” where we add the extern\include subfolder of our MATLAB installation as an additional include directory
Now we go to the “Configuration Properties” -> “Linker” settings where we add the extern\lib\win64\microsoft\ subfolder of our MATLAB installation as an additional library directory:
The last step we have to take is to navigate to “Configuration Properties” -> “Linker” -> “Input” and add libmx.lib, libmat.lib and libeng.lib as additional dependencies.
Press OK and start the build process. It should work just fine and the application should start running. In addition you might obtain the following error
This is good, since the application compiles fine and runs but it cannot find additional dependencies which can be found in the bin\win64 sub folder of your MATLAB installation.
So you can either add this folder to your environment variable %PATH% or you can setup your Visual Studio to honor that path during runtime. To do so go to the project properties again and select “Configuration Properties” -> “Debugging” and add the path to the bin\win64 subfolder of your MATLAB installation to your environment variable PATH.

More Answers (0)

Categories

Find more on C Shared Library Integration in Help Center and File Exchange

Products


Release

R2011b

Community Treasure Hunt

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

Start Hunting!