Problems including MATLAB "engine.h" for C++ code - c++

I am trying to run the example code from the MATLAB Doc, but when I try to build the project in Visual Studio I get this error
fatal error C1083: Cannot open include file: 'engine.h': No such file or directory
The fact is that in the Doc I cannot find where to find the header to link it, they show the examples as if there was no need to do anything else, just do the
#include "engine.h";
Any ideas about how to solve this issue?
EDIT
I solved the first problem but now I get some errors reated to missing libs:
1>engwindemo.obj : error LNK2019: unresolved external symbol _engClose referenced in function _main
1>engwindemo.obj : error LNK2019: unresolved external symbol _mxGetClassName referenced in function _main
1>engwindemo.obj : error LNK2019: unresolved external symbol _engGetVariable referenced in function _main
1>engwindemo.obj : error LNK2019: unresolved external symbol _engOutputBuffer referenced in function _main
1>engwindemo.obj : error LNK2019: unresolved external symbol _mxDestroyArray referenced in function _main
1>engwindemo.obj : error LNK2019: unresolved external symbol _engEvalString referenced in function _main
1>engwindemo.obj : error LNK2019: unresolved external symbol _engPutVariable referenced in function _main
1>engwindemo.obj : error LNK2019: unresolved external symbol _mxGetPr referenced in function _main
1>engwindemo.obj : error LNK2019: unresolved external symbol _mxCreateDoubleMatrix_730 referenced in function _main
1>engwindemo.obj : error LNK2019: unresolved external symbol _engOpen referenced in function _main
I set the Path variable as told in the documentation, set the lib path and added some libraries and now I don't know what else can I do. I also rebooted VisualStudio in order to make the Path variable change effective.
Thanks in advance.

I finaly solved the problem. I was building a WIN32 project, while matlab is x64, so VisualStudio gives errors when you try to link 64-bit platforms. The solution is changing the Active Solution Platform to x64, inside Project Properties -> Configuration Manager.
It is well explained in the following link.
Thanks anyway for the answers, they were useful.
So, summarizing, to be able to compile and run a c++ code in VisualStudio2008 and Matlab2010 with engine.h, the following steps are required:
1.- Set Path variable in Advanced System Settings-> environment variables: C:\Program Files\MATLAB\R2010a\bin\win64 (or the path where libeng.dll is located)
2.- In project properties of VisualStudio, link in Additional Include directories of C++->General:
"C:\Program Files\MATLAB\R2010a\extern\include"
3.- In project properties, linker->general, Additional Library Directories:
"C:\Program Files\MATLAB\R2010a\extern\lib\win64\microsoft"
4.- Add the following libraries in Linker->Additional Dependencies:
libeng.lib
libmx.lib
5.- Change the Active Solution Platform to x64, in Configuration Manager as explained in the link.

Have you added the MATLAB include directory to your project's include path?
. The directory should be like "C:\Program Files\MATLAB\R2010a\extern\include"

In case you forgot, add the folder containing libmat.dll libmx.dll etc. to your path. For me that was:
C:\Program Files\MATLAB\R2012a\bin\win64

While the Jav_Rock's answer is completely correct, I want to add information about one of the points:
1.- Set Path variable in Advanced System Settings-> environment variables: C:\Program Files\MATLAB\R2010a\bin\win64 (or the path where
libeng.dll is located)
I spent three hours to understant what does it means, so I want to clarify this moment for future researchers.
You need to add the path of MATLAB Engine dll libraries to your Windows.
We can do it this way:
My Computer -> right click: Settings. Opened System window. Left bottom corner: Advanced System Settings
Advanced Tab
In the Environment variables for your user press Create... button and add this one:
Variable name: PATH
Variable value: C:\Program Files\MATLAB\R2016a\bin\win64
This path is reference on where is your libeng.dll located.
Important moment: it can require to restart VS or even restart computer.

Related

Linker Error prevents me from initializing TA-LIB in C++

I'm having a problem with TA-LIB in my C++ project.
I just downloaded TA-lib (ta-lib-0.4.0-msvc.zip) and copy-and-pasted c folder to my project folder.
Because of a linker error, I can't go any further.
What I did:
I just downloaded TA-lib (ta-lib-0.4.0-msvc.zip) and copy-and-pasted c folder to my project folder.
include "c\include\ta_libc.h"
Is there anything wrong with my steps? Or any steps I missed?
#AlenL
Thank you for your help.
I included every proj files in IDE.
But the result is the same.
+) Error List
LNK2019 unresolved external symbol _TA_Shutdown referenced in function _main
LNK2019 unresolved external symbol _TA_Initialize referenced in function _main
LNK1120 2 unresolved externals
Look into the ta-lib\c\ide\vs2005\lib_proj folder and it's subfolders. You need to include the .vcproj files from the subfolders into your solution.

Including Lua in VS2015 C++ Project

I would like to integrate Lua into my current C++ application I build with VisualStudio 2015 (x64 mode).
I grabbed a simple Lua wrapper from here, and the Lua binaries for windows x64 from here (the lua-5.1.5_Win32_dll14_lib.zip one).
Next, I added the include and library path to the project preferences. Works so far in the IDE. However, when I try to compile the code it throws 24 errors (like these first two):
1>LuaScript.obj : error LNK2019: unresolved external symbol "lua_close" referenced in function ""public: __cdecl LuaScript::~LuaScript(void)" (??1LuaScript##QEAA#XZ)".
1>LuaScript.obj : error LNK2019: unresolved external symbol "lua_gettop" referenced in function ""public: void __cdecl LuaScript::clean(void)" (?clean#LuaScript##QEAAXXZ)".
which tells me next to nothing. Seems that the linker is unable to find the library but the includes are working and the path to library is set, too. Any suggestions what I might have missed or should look into? Any hint would be appreciated!

Installing GLFW 3.0 not working Visual Studio

I'm trying to create a GLFW project, but I'm getting LNK2019 errors with the basic setup.
I've downloaded the latest binary (glfw-3.0.bin.WIN32.zip) to a folder.
I've created a new, empty console project.
Within VC++ Directories, I've added the following line to include directories:
C:\C++Libraries\glfw-3.0.bin.WIN32\include
I've added the following line to the Library Directories:
C:\C++Libraries\glfw-3.0.bin.WIN32\lib-msvc110
I've linked the following libraries:
opengl32.lib, glfw3.lib, glfw3dll.lib
From the latest tutorial, I paste into my project (no visible syntax errors) to test, but I get four LNK2019 errors after trying to run it.
Here are the errors:
Error 2 error LNK2019: unresolved external symbol __imp__joyGetPosEx#8
referenced in function __glfwPlatformGetJoystickAxes
c:\Users\Spicy Weenie\documents\visual studio 2012\
Projects\Beta\Beta\glfw3.lib(win32_joystick.obj)
Error 3 error LNK2019: unresolved external symbol __imp__joyGetDevCapsW#12
referenced in function __glfwPlatformGetJoystickAxes
c:\Users\Spicy Weenie\documents\visual studio
2012\Projects\Beta\Beta\glfw3.lib(win32_joystick.obj)
Error 4 error LNK2019: unresolved external symbol __imp__joyGetPos#8
referenced in function __glfwPlatformJoystickPresent
c:\Users\Spicy Weenie\documents\visual studio
2012\Projects\Beta\Beta\glfw3.lib(win32_joystick.obj)
Error 1 error LNK2019: unresolved external symbol __imp__timeGetTime#0
referenced in function __glfwInitTimer c:\Users\Spicy Weenie\documents\visual
studio 2012\Projects\Beta\Beta\glfw3.lib(win32_time.obj)
You need to link in at least winmm.lib for timeGetTime. The joystick code is probably in there to.

unresolved external symbol __imp__Inf and __imp__Nan

I just tried to build Qt for WinCE7.0 using VS2008 after lots of code modification I successfully compiled main libraries.
While Compiling the QtScript library I received the following linker errors:
1>Linking...
1> Creating library ..\..\lib\QtScript4.lib and object ..\..\lib\QtScript4.exp
1>BytecodeGenerator.obj : error LNK2019: unresolved external symbol __imp__Inf referenced in function "public: static double __cdecl QTWTF::FloatHashTraits<double>::emptyValue(void)" (?emptyValue#?$FloatHashTraits#N#QTWTF##SANXZ)
1>Executable.obj : error LNK2001: unresolved external symbol __imp__Inf
1>MathObject.obj : error LNK2001: unresolved external symbol __imp__Inf
1>DateMath.obj : error LNK2019: unresolved external symbol __imp__Nan referenced in function "double __cdecl QTWTF::parseDateFromNullTerminatedCharacters(char const *,bool &,int &)" (?parseDateFromNullTerminatedCharacters#QTWTF##YANPBDAA_NAAH#Z)
1>JSValue.obj : error LNK2001: unresolved external symbol __imp__Nan
1>..\..\lib\QtScript4.dll : fatal error LNK1120: 2 unresolved externals
I have absolutely no idea which libraries I missed to link with!
Thanks
If you're using Windows, I'll assume you're building in MSVS. I often start projects WITHOUT default libs and if I happen to touch "out of reach" terriotry from another lib, I add what I need as I go along.
Fortunately, MSVS is great at helping me with this. Just turn VERBOSE compiling status and see what libs it's trying to access, then just add them:
right click the project, linker, show progress -> select VERBOSE
Another method is when I check MSDN for Microsoft functions and see the lib they are declared in and add it (since VERBOSE can be overkill on my poor output window). I don't know if Qt has a detailed reference documentation (also stating the libs) but it's worth a shot.
When all else fails, just add all libs Qt could possibly want (make sure IGNORE STANDARD LIBS is disabled) then check VERBOSE and only keep those in the list.
Assuming you have all the libraries in the project, another problem is mismatched dependencies (right click the solution, startup project -> select the one you need, [project dependencies -> map each dependency for the specified libs).
Also make sure when you import an extern the lib is defined in Linker->Input.
However, if you modified the source (either adding new functions/global or static vars or you modified function signatures), the unresolved external reference means a function/var definition has no associated body. Either implement one or add { } in the definition; so if that's the case, check the functions/vars from the error message.

fftw in Visual Studio?

I'm trying to link my project with fftw and so far, I've gotten it to compile, but not link. As the site said, I generated all the .lib files (even though I'm only using double precision), and copied them to C:\Program Files\Microsoft Visual Studio 9.0\VC\lib, the .h file to C:\Program Files\Microsoft Visual Studio 9.0\VC\include and the .dll to C:\windows\system32.
I've copied the tutorial program, and the exact error I am getting is:
1>hw10.obj : error LNK2019: unresolved external symbol __imp__fftw_free referenced in function "bool __cdecl test(void)" (?test##YA_NXZ)
1>hw10.obj : error LNK2019: unresolved external symbol __imp__fftw_destroy_plan referenced in function "bool __cdecl test(void)" (?test##YA_NXZ)
1>hw10.obj : error LNK2019: unresolved external symbol __imp__fftw_execute referenced in function "bool __cdecl test(void)" (?test##YA_NXZ)
1>hw10.obj : error LNK2019: unresolved external symbol __imp__fftw_plan_dft_1d referenced in function "bool __cdecl test(void)" (?test##YA_NXZ)
1>hw10.obj : error LNK2019: unresolved external symbol __imp__fftw_malloc referenced in function "bool __cdecl test(void)" (?test##YA_NXZ)
So, what could be wrong with my project setup? Thanks!
My case
Using FFTW in Visual Studio 2010
Precompiled FFTW 3.3.1 Windows DLLs install using fftw-3.2.1-dll.zip, on my Windows XP machine.
Open cmd window and go to lib.exe folder C:\Program Files\Microsoft Visual Studio 10.0\VC\bin>
Type lib /def:libfftw3-3.def
Type lib /def:libfftw3f-3.def
Type lib /def:libfftw3l-3.def
If you have a error on command, copy any mspdb80.dll or mspdb100.dll file to in bin directory.
You will get 6 files
libfftw3-3.exp, libfftw3-3.lib, libfftw3f-3.exp, libfftw3f-3.lib,
libfftw3l-3.exp and libfftw3l-3.lib
and copy it to programming directory.
Delete all mspdb80.dll or mspdb100.dll file from bin directory.
Closed Project and open again and rebuild it again.
Have you actually linked against the library in the project you're building?
Project -> Properties -> Linker -> Input -> Additional dependencies
You need to add the library's filename to that field.
Assuming you've actually linked your project against the lib and it doesn't work, use /verbose:lib and paste the output of that and the output of
dumpbin /exports fftw.lib | findstr fftw_free
I had similar problem. What helped was compiling the fftw libs with this help Compiling FFTW source in Visual studio. Actually more closely the problem was compiling my application Win 32 and trying to use x64 -libraries. So make sure the platform is same.