# call matlab engine from c++

Engine* engOpen(const char* startcmd)启动Matlab引擎

int engClose(Engine* ep) 关闭Matlab引擎

int engSetVisible(Engine* ep,bool value) 显示或隐匿窗口

int engEvalString(Engine* ep, const char* string)执行Matlab表达式

mxArray* engGetArray(Engine* ep, const char* name)获取一个变量数组的值

int engPutArray(engine* ep, const mxArray* mp)设置一个变量数组的值

int engPutVariable(Engine *ep, const char *name, const mxArray *pm)同上

mxArray *engGetVariable(Engine *ep, const char *name)获取一个变量

int engOutputBuffer(Engine* eP，char* p，int n)获取输出字符串

#include<Windows.h>
/*********************************

*******************************/
#include"engine.h"

#pragma comment(lib,"libeng.lib")
#pragma comment(lib,"libmx.lib")
#pragma comment(lib,"libmat.lib")

int main(int argc, _TCHAR* argv[])
{
Engine* pEng=NULL;
if(!(pEng=engOpen(NULL)))
{
printf("Open matlab engine fail!\n");
return 0;
}
else
printf("Open Engine Sucess!\n");
engSetVisible(pEng,0);//隐藏matlab窗口

mxArray *A=NULL;
double init=2;
A=mxCreateDoubleMatrix(1,1,mxREAL);
memcpy((void*)mxGetPr(A),(void*)&init,sizeof(double));
engPutVariable(pEng,"A",A);

init = 1;
memcpy((void*)mxGetPr(A),(void*)&init,sizeof(double));
engPutVariable(pEng,"B",A);

mxDestroyArray(A);

//Sleep(3*60*1000);
printf("start to create the fig\n");
engEvalString(pEng,"t=0:0.2:7;plot(t,sin(t));");
engEvalString(pEng,"figure;");
engEvalString(pEng,"plot(t,A*cos(t)+B);");
printf("Engine will be closed\n");
system("pause");
if(NULL!=pEng)
engClose(pEng);
printf("Engine is closed");
return 0;
}


http://blog.csdn.net/u010177286/article/details/45276315

# How can I suppress MATLAB’s command window when calling it from c++/ Java?

int engSetVisible(Engine *ep, bool value);

int engGetVisible(Engine *ep, bool *value);

https://zhuanlan.zhihu.com/p/24886395

# VS: fatal error LNK1158: cannot run ‘rc.exe’

Found this on Google… I would assume that in your case you would copy rc.exe and rcdll.dllto visual studio 2012\vc\bin or wherever you have it installed:

Part 2: FIX LINK : fatal error LNK1158: cannot run ‘rc.exe’

C:\Program Files (x86)\Windows Kits\8.0\bin\x86

Copy these files:

rc.exe
rcdll.dll

From

C:\Program Files (x86)\Windows Kits\8.0\bin\x86

To

C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin

Or I also found this:
Microsoft left a few things out of their MSVT package. Since no one knows whether they were left out by mistake or for license reasons, no one with MSVC is too interested in giving them out. A few Google searches turn up some tricky sources. Fortunately, Microsoft has finally wised up and solved this problem and many more.

http://msdn.microsoft.com/vstudio/express/support/faq/default.aspx#pricing

http://msdn.microsoft.com/vstudio/express/support/install/

A good amount of MSVT missing files are there but the missing SDK files aren’t.

and this:
I had the same problem which I solved by doing this:

1. Installing the Microsoft .Net Framework 2.0
2. Adding the path of the .NET Framework files (for me “C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727”) to Global compiler settings > Programs > Additional Paths within Code::Blocks.

Now I can build and link resource files without errors.

https://stackoverflow.com/a/14373113/4862158

# The problems on config libigl

Severity Code Description Project File Line Suppression StateSeverity Code Description Project File Line Suppression StateError C4996 ‘fopen’: This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. MyMotionRetargeting d:\igl\mymotionretargeting\mymotionretargeting\dependencies\libigl\include\igl\writeOBJ.cpp 33

c/c++ Preprocessor=>Preprocessor Definitions

_CRT_SECURE_NO_WARNINGS

LINK : fatal error LNK1158: cannot run ‘rc.exe’

Good Solution:

Add the path that contains the ‘rc.exe’ to system environment ‘path’

I’m on Windows 7 x64 and Visual Studio 2017. I get this error trying to compile a cython script. That’s how I solved: I copied and pasted rc.exe and rcdll.dll from:

C:\Program Files (x86)\Windows Kits\8.1\bin\x86


to

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64

These instructions are for 32-bit. For 64-bit, try C:\Program Files (x86)\Windows Kits\8.1\bin\x64to C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64

Solution2:

This can be caused by a vcxproj that originated in previous versions of Visual Studio OR changing the Platform Toolset in Configuration Properties -> General.

If so, possible Solution:

1) Go to Configuration Properties -> VC++ Directories

2) Select drop down for Executable Directories

3) Select “Inherit from parent or Project Defaults”

https://stackoverflow.com/a/47875022/4862158

# Setting Up GLEW for Visual Studio

1. Go to GLEW main page and download Windows binaries. Current link is this for now (12/04/2016).
2. Extract the file (Preferably into “Dependencies” folder of the project.

1. Copy path of include (SomeOtherStuff\glew-VER.NUM\include\GL). For me it’s …\dependencies\glew-1.13.0\include\GL
2. Go to your project opened in Visual Studio
3. Go to Project Properties -> Configuration Properties -> C/C++ -> General -> Additional Include Directories
4. Paste the path, be sure path is correct. Click OK (and Apply)

1. Copy path of .lib files. In here, if your project is 64-bit (x64), you should copy path of 64-bit folder (The path will be something like …\dependencies\glew-1.13.0\lib\Release\x64). If your project is 32-bit (Win32), then you should use path of 32-bit (something like …\dependencies\glew-1.13.0\lib\Release\Win32)
2. Go to your project opened in Visual Studio
3. Go to Project Properties -> Configuration Properties -> Linker -> General -> Additional Library Directories
4. Paste the path and click OK (and Apply).
5. Finally, go to Project Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies and type the next there things: opengl32.lib glu32.lib glew32.lib
6. Click OK, then Apply, and then OK. Hopefully, you are good to go.

Troubleshooting

Compile Time:

If you are sure you did everything correctly but, still have some unidentified problems, try to replace glew32.lib with glew32s.lib, and add #define GLEW_STATIC beginning of your code.

Run Time:

If it says something like “glew32.dll is missing”, just go to bin folder related with your project (64 or 32 bit), and copy-paste the dll into the same directory you .exe is located i.e. Debug file.

http://www.mcihanozer.com/tips/setting-up-libraries/setting-up-glew-for-visual-studio/

# Setting Up GLEW for Visual Studio

1. Go to GLEW main page and download Windows binaries. Current link is this for now (12/04/2016).
2. Extract the file (Preferably into “Dependencies” folder of the project.

1. Copy path of include (SomeOtherStuff\glew-VER.NUM\include\GL). For me it’s …\dependencies\glew-1.13.0\include\GL
2. Go to your project opened in Visual Studio
3. Go to Project Properties -> Configuration Properties -> C/C++ -> General -> Additional Include Directories
4. Paste the path, be sure path is correct. Click OK (and Apply)

1. Copy path of .lib files. In here, if your project is 64-bit (x64), you should copy path of 64-bit folder (The path will be something like …\dependencies\glew-1.13.0\lib\Release\x64). If your project is 32-bit (Win32), then you should use path of 32-bit (something like …\dependencies\glew-1.13.0\lib\Release\Win32)
2. Go to your project opened in Visual Studio
3. Go to Project Properties -> Configuration Properties -> Linker -> General -> Additional Library Directories
4. Paste the path and click OK (and Apply).
5. Finally, go to Project Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies and type the next there things: opengl32.lib glu32.lib glew32.lib
6. Click OK, then Apply, and then OK. Hopefully, you are good to go.

Troubleshooting

Compile Time:

If you are sure you did everything correctly but, still have some unidentified problems, try to replace glew32.lib with glew32s.lib, and add #define GLEW_STATIC beginning of your code.

Run Time:

If it says something like “glew32.dll is missing”, just go to bin folder related with your project (64 or 32 bit), and copy-paste the dll into the same directory you .exe is located i.e. Debug file.

http://www.mcihanozer.com/tips/setting-up-libraries/setting-up-glew-for-visual-studio/

# How to remove space after image caption

A quick way would be to use \vspace{} with negative length as input. However, this is not the right approach and is not recommended for use.

Without using vspace the output would look like:

Here is a MWE with vspace and negative length as input followed by the output.

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{xcolor}

\begin{document}

\begin{figure}[!ht]
\centering
\includegraphics[width=0.5\textwidth]{image}
\vspace{-1em}
\caption{\textcolor{gray}{\footnotesize \textit{ImageCaption}}}
\vspace{-1.5em}
\end{figure}
This is first text after caption.

\end{document}

Note how the use of vspace after the figure and after the caption shrinks the space.

https://tex.stackexchange.com/a/100131