MATLAB Compiler getting stuck during build process - matlab

I built a GUI in MATLAB that makes use of the Instrument Control Toolbox, among other things. I tried to compile this GUI with deploytool but it's getting stuck during the compile:
ant:
<mkdir dir="Z:\My Path\MyApp\distrib" />
<mkdir dir="Z:\My Path\MyApp\src" />
mcc -o MyApp -W WinMain:MyApp -T link:exe -d 'Z:\My Path\MyApp\src' -N -p instrument -w enable:specified_file_mismatch -w enable:repeated_file -w enable:switch_ignored -w enable:missing_lib_sentinel -w enable:demo_license -v 'Z:\My Path\MyApp.m'
Compiler version: 4.18.1 (R2013a)
Processing C:\Program Files\MATLAB\R2013a\toolbox\matlab\mcc.enc
Processing C:\Program Files\MATLAB\R2013a\toolbox\instrument\mcc.enc
Processing C:\Program Files\MATLAB\R2013a\toolbox\shared\instrument\mcc.enc
Processing include files...
2 item(s) added.
Processing directories installed with MCR...
The file Z:\My Path\MyApp\src\mccExcludedFiles.log contains a list of functions excluded from the CTF archive.
0 item(s) added.
Generating MATLAB path for the compiled application...
Created 54 path items.
And that's all she wrote. Of note, the final statement of "Created 54 path items" to me doesn't make a whole lot of sense, since I don't have 54 dependencies.
I changed the path that the code is on to Z:\My Path\MyApp to be generic. It may or may not be important but there are spaces in the path. I mentioned this because maybe that's my problem. Z:\ is a network drive instead of a local drive. Some dependencies live on R:\, which is also a network drive. All dependencies are on the MATLAB path or in my local folder.
I'm using MATLAB R2013a x64 and the Windows SDK 7.1 (used mbuild -setup to set this).
The deploytool and MATLAB are both responsive - I can cancel the build process with no problem. I ran the mcc code verbatim as above and it's still stuck in the same place with no indication that it's working. Hitting CTRL-C to interrupt it gives no error messages or anything.
Does anyone know what's going on? It must be something to do with the mcc call, I'm sure of it.

It looks like this problem is due to my license file being located on a network server rather than locally. Working with MathWorks tech support really helped out here.
When using mcc, specify a local license file with the -Y flag. The compile then goes from 20 minutes or so to about 2. An example call:
mcc -m -v -N -Y alpha.lic myApp.m

Related

MATLAB - Error creating maxmaci64 from jpeg_write.c

I had problems making mexmaci64 files using Mex from both jpeg_read.c and jpeg_write.c from jpeg toolbox. I asked my question here and the problem for jpeg_read solved.
but I still have a different error when I compile jpeg_write.c.
everything is the same and I didn't change any path or anything.
I don't understand why Matlab console returns this error.
Is this familiar to anybody? please let me know.
>> mex -compatibleArrayDims -I/usr/local/Cellar/jpeg/9d/include jpeg_write.c -L/usr/local/Cellar/jpeg/9d/lib -ljpeg
Building with 'Xcode with Clang'.
Error using mex
/Users/folder/jpeg_toolbox/jpeg_write.c:56:10: fatal error: 'jpegint.h' file not found
#include <jpegint.h>
^~~~~~~~~~~
1 error generated.
First off:
By pointing at the /usr/local/Cellar/jpeg/<version>/include location of the jpeg or other libraries, you're dependent on the specific version that is currently installed. You probably want to use /usr/local/opt/jpeg/include/ etc instead. /usr/local/opt is where Homebrew exposes its non-versioned presentations of its installed package contents.
So:
mex -compatibleArrayDims -I/usr/local/Cellar/jpeg/9d/include ...
This is pointing at the jpeg library. Does the jpeg library supply jpegint.h?
$ ls /usr/local/Cellar/jpeg/9d/include/
jconfig.h jerror.h jmorecfg.h jpeglib.h
Nope. So that's why it's not found. So you have to figure out where you can actually get jpegint.h from. Hit Google and consult your documentation to figure out what library you're actually trying to pull jpegint.h from, and pull that in, too, with the appropriate -I, -L, and -l flags.
If you think you have it already installed, you can use find /usr/local/Cellar -name jpegint.h to look for it. I found it in the gdcm package.
[~] $ find /usr/local/Cellar -name jpegint.h
/usr/local/Cellar/gdcm/3.0.8_1/include/gdcm-3.0/gdcmjpeg/jpegint.h
So you probably want something like:
mex -compatibleArrayDims -I/usr/local/opt/jpeg/include ...
-I/usr/local/opt/gdcm/include/gdcm-3.0/gdcmjpeg ...
jpeg_write.c ...
-L/usr/local/opt/jpeg/lib -L/usr/local/opt/gdcm/lib ...
-ljpeg -lgdcmjpeg16
(I don't know if you actually want -lgdcmjpeg8, -lgdcmjpeg12, or -lgdcmjpeg16, or maybe something else. I'm just guessing here. Consult the GDCM documentation.)

Link to gfortran for mex file

I am trying to create mex files for using some C++ code in Matlab, but running into an error with the compilation which, I guess, goes beyond Matlab. I am on Windows.
The example I'm struggling with is the Mex Interface example in the Armadillo library for linear algebra, available: here. The Matlab file is what I'm running and it looks like this:
% Compile the demo as a mex file
mex -lgfortran armaMex_demo.cpp -I/path/to/armadillo
The error I get is:
Error using mex
MEX cannot find library 'gfortran' specified with the -l option.
MEX looks for a file with one of the names:
libgfortran.lib
gfortran.lib
Please specify the path to this library with the -L option.
Trying some things I found online, I installed MinGW and cygwin64 and added the paths to their bin folders to my PATH variable. Before that I also installed MinGW via Matlab.
My question: How do I get it to link with gfortran?
If I search C:for libgfortran I find some files, but none of them have the file ending .lib (but e.g. .dll and .a) and if I search for gfortranI find some .exe files but again, no .lib file. If I run gfortran -dumpversion in the terminal, I get 4.9.3 back, so it is obviously there somewhere. I am obviously missing something, and this is really not my forte, to say the least.

Suppress "program not found" errors in Eclipse CDT

Most of my team uses a .bat file to set paths and then run a build. The .bat file allows selection of multiple different compiler/target platforms, but all use some version of GCC/G++ or similar compiler.
I created an Eclipse project that simply uses the .bat file rather than re-inventing the wheel and tracking down all the paths needed for each build (which I'd need to update if anyone ever updated the .bat file anyway).
This works great for building, and I can even see compiler errors/warnings, but there are some extra errors always present:
Program "gcc" not found in PATH
Program "g++" not found in PATH
I've seen many questions about these and similar errors, but in those case the user couldn't build, and the solution was to install the tools and/or update their PATH or Eclipse environment settings. I don't want to do that; all the tools I need are installed, and the .bat file works just fine to set the PATH for building. Is there a way to suppress these errors, or have Eclipse not try to find the compiler executable, since the build succeeds anyway?
Edit: As suggested in the answer I've received so far, here is output on the console after putting a full path to a compiler in the global discovery settings, which isn't exactly my favorite solution even if it worked, but I'll probably deal with it. Regardless the errors don't go away:
15:27:24 **** Running scanner discovery: CDT GCC Built-in Compiler Settings MinGW ****
"C:\\redacted\\localapps\\MinGW5\\bin\\g++.exe" -E -P -v -dD C:/Project_Files/redacted/code_workspaces/redacted/.metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.C
Reading specs from C:/redacted/localapps/MinGW5/bin/../lib/gcc/mingw32/3.4.2/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchronization --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.2 (mingw-special)
C:/redacted/localapps/MinGW5/bin/../libexec/gcc/mingw32/3.4.2/cc1plus.exe -E -quiet -v -P -iprefix C:\redacted\localapps\MinGW5\bin\../lib/gcc/mingw32/3.4.2/ C:/Project_Files/redacted/code_workspaces/redacted/.metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.C -dD
ignoring nonexistent directory "C:/redacted/localapps/MinGW5/bin/../lib/gcc/mingw32/3.4.2/../../../../mingw32/include"
#define __cplusplus 1
ignoring nonexistent directory "/mingw/lib/gcc/mingw32/../../../include/c++/3.4.2"
#define __STDC_HOSTED__ 1
ignoring nonexistent directory "/mingw/lib/gcc/mingw32/../../../include/c++/3.4.2/mingw32"
#define __GNUC__ 3
ignoring nonexistent directory "/mingw/lib/gcc/mingw32/../../../include/c++/3.4.2/backward"
...
And then a bunch of #defines
The command string I used in the discovery options for this output was C:\redacted\localapps\MinGW5\bin\${COMMAND}.exe ${FLAGS} -E -P -v -dD "${INPUTS}".
Based on the information provided, these errors are coming from the scanner discovery part of CDT.
On my machine the full error looks like this:
Description Location Type
Program "g++" not found in PATH Preferences, C++/Build/Settings/Discovery, [CDT GCC Built-in Compiler Settings MinGW] options C/C++ Scanner Discovery Problem
Program "gcc" not found in PATH Preferences, C++/Build/Settings/Discovery, [CDT GCC Built-in Compiler Settings MinGW] options C/C++ Scanner Discovery Problem
Or as a screenshot
What is going on here is Eclipse CDT is (attempting to) launch GCC and G++ to find out what the global settings are for things like include paths, etc.
To fix the problem, go to the Location specified in the error message and adjust the scanner settings. Here is the matching setting to go with the specific error I received.
Your error might be in the project or in the global settings.
To update the MinGW setting, you can provide the path to a batch file that looks like GCC/G++ but sets up your environment correctly first, or you can point directly at the GCC that Eclipse CDT did not find on its own.
For example you can have:
D:\path\to\my\compilers\${COMMAND}.exe ${FLAGS} -E -P -v -dD "${INPUTS}"
As the setting instead of the default.
To aid the debugging, check the Allocate console in the Console View to see exactly what is being run and what output is being generated.
And here is what you might see when it does not work. Hopefully the error messages in the console are sufficient to resolve the problem on your machine.
21:12:54 **** Running scanner discovery: CDT GCC Built-in Compiler Settings MinGW ****
"D:\\path\\to\\my\\compilers\\g++.exe" -E -P -v -dD C:/Temp/workspace/.metadata/.plugins/org.eclipse.cdt.managedbuilder.core/spec.C
Cannot run program "D:\path\to\my\compilers\g++.exe": Launching failed
Error: Program "D:\path\to\my\compilers\g++.exe" not found in PATH
PATH=[\bin;\bin; -- snip --]
21:12:54 Build Finished (took 37ms)
Here is a screenshot to match:
If it does work, you should see lots of #defines and the like showing the global state of your compiler.

Can a mex s-function component be recompiled only if it changed?

In the first phase of testing my code has to run in a Matlab Simulink environment (2010b 32bits) compiled as S-function. The compiler is the one that comes with Visual Studio 2010.
I currently have a script that compiles my code that looks like this:
mex -c -v foo_main.c
mex -c -v foo_1.c
mex -c -v foo_2.c
% etc...
mex -v foo_wrapper.c foo_main.obj foo_1.obj foo_2.obj % etc...
During the years the number of files has greatly increased, to the extent that compilation takes quite some time.
My question is: does it exists a method to check if an *.obj does not correspond to its *.c counterpart and recompile it only when necessary?
I am wary of creating special scripts because I would have to change them on a case-by-case basis and I see this as a road prone to errors and unnecessary risks.
EDIT:
My current solution is to take the date property of the files and compare them:
c_file = dir(fullfile(pwd,'\\foo.c'));
obj_file = dir(fullfile(pwd,'\\foo.obj'));
if (datenum(c_file.date) > datenum(obj_file.date))
mex -c -v foo.c
end
I understand that this is not the cleanest solution and, in the comments, m.s. suggests to use a nmake file. I never created one and I do not know how to use it from a Matlab script.
Can it be done? Which steps should I follow to create and use it?

How to change MATLAB path to compile mex files of FLANN with cmake command?

I try to compile FLANN on a remote machine which I am not a root user. For this purpose I compiled cmake at my home and set an alias to call. I also downloaded FLANN from web and process the compilation as it is suggested at the manual.
mkdir build
cd build
cmake ..
make
It is compiled without an error but the matlab module and mex compilation. Even I add the matlab bin into $PATH it gives following warning after cmake ...
...
CMake Warning at src/matlab/CMakeLists.txt:57 (message):
The 'mex' and 'mexext' programs have been found in different locations.
It's likely that one of them is not part of the MATLAB instalation. Make
sure that the 'bin' directory from the MATLAB instalation is in PATH
...
Because of this issue, matlab mex files are not compiled when I execute make.
I could not solve this problem in any way even I tried to set some cmake configurations. Is there any suggestion to deal with this compilation problem?
echo $PATH
/home/y/bin:/usr/kerberos/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/bin:/usr/bin:/usr/local/matlab/bin
which mex
/usr/local/bin/mex
which mexext
/usr/local/matlab/bin/mexext
An alternative solution (that worked for me) is to create a symbolic link for mexext in /usr/local/bin that points to where mexext is actually found.
sudo ln -s /usr/local/MATLAB/R2016a/bin/mexext /usr/local/bin/mexext
(The solution is in the comments. See Question with no answers, but issue solved in the comments (or extended in chat) )
The OP wrote:
I solved the problem by taking the matlab path to first place on $PATH