c++ mex file in matlab - matlab

I am trying to call a c++ function from matlab using a mex file.
While compiling any example mex programs given in the <root>\extern\examples\mex folder I get the same error:
Creating library C:\USERS\SONY\APPDATA\LOCAL\TEMP\MEX_AA~1\templib.x and object C:\USERS\SONY\APPDATA\LOCAL\TEMP\MEX_AA~1\templib.exp
arrayProduct.obj : error LNK2001: unresolved external symbol _fltused
LINK : error LNK2001: unresolved external symbol _DllMainCRTStartup
arrayProduct.mexw64 : fatal error LNK1120: 2 unresolved externals
I am using matlab 7.8(2009a) and compiler microsoft visual studio express 2008.
Can someone please help me?
Thanks.

Related

Why does my code fail to buld with Mex but work with cl?

Hey so I'm working to attach a piece of hardware into a setup controlled with MATLAB. I've written a set of functions (tried both C and C++) that utilize this hardware to perform simple tasks.
The code compiles just fine using cl. When I try to compile with mex however, it cannot seem to link symbols from my includes (am using the -I flag pointing to directory of my header files).
Any thoughts?
CL Output:
>cl isConnected.c *.lib
Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29334 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
isConnected.c
Microsoft (R) Incremental Linker Version 14.28.29334.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:isConnected.exe
isConnected.obj
ArenaCd_v140.lib
ArenaC_v140.lib
isConnectedMex.lib
SaveCd_v140.lib
SaveC_v140.lib
MATLAB Output:
>> curDir = pwd;
>> linkPath = ['-L' fullfile(curDir,'\lib64\ArenaC\ArenaC_v140.lib')];
>> incPath = ['-I' fullfile(curDir,'\include\ArenaC')];
>> exist(linkPath(3:end))
ans = 2
>> exist(incPath(3:end))
ans = 7
>> % Paths Are Correctly named it seems
>> mex('isConnectedMex.c',incPath,linkPath)
Building with 'Microsoft Visual C++ 2019 (C)'.
Error using mex
Creating library isConnectedMex.lib and object isConnectedMex.exp
isConnectedMex.obj : error LNK2019: unresolved external symbol __imp_acOpenSystem referenced in function main
isConnectedMex.obj : error LNK2019: unresolved external symbol __imp_acGetLastErrorMessage referenced in function main
isConnectedMex.obj : error LNK2019: unresolved external symbol __imp_acSystemUpdateDevices referenced in function main
isConnectedMex.obj : error LNK2019: unresolved external symbol __imp_acSystemGetNumDevices referenced in function main
isConnectedMex.mexw64 : fatal error LNK1120: 4 unresolved externals
The functions referenced by MATLAB errors are #include in one of my headers. Using -v option with MEX though it shows these folders are being included. Any help would be greatly appreciated!!
Edit: Adding cl and mex commands used. The only difference between isConnected.c and isConnectedMex.c is that isConnectedMex.c uses the mexFunction call as it's main method.
The -L option is to specify a directory where the linker can find required library files. You need to use the -l option (lowercase L) to specify which libraries to link. This is what it looks like:
mex isConnectedMex.c -Iinclude\ArenaC -Llib64\ArenaC -lArenaC_v140
Or, if the lib file is a static library, you can pass it as an input file:
mex isConnectedMex.c lib64\ArenaC\ArenaC_v140.lib -Iinclude\ArenaC

Allegro Installation

I've been trying to install allegro 5 into MSVS 2015 for 3 hours now, and have seen many tutorials, none of which helped me. I am using the code on the tutorial wiki to just make a screen.
#include "windows.h"
#include <stdio.h>
#include <allegro5/allegro.h>
int main(int argc, char **argv)
{
ALLEGRO_DISPLAY *display = NULL;
if (!al_init()) {
fprintf(stderr, "failed to initialize allegro!\n");
return -1;
}
display = al_create_display(640, 480);
if (!display) {
fprintf(stderr, "failed to create display!\n");
return -1;
}
al_clear_to_color(al_map_rgb(0, 0, 0));
al_flip_display();
al_rest(10.0);
al_destroy_display(display);
return 0;
}
This is the error I get.
1>------ Build started: Project: Project7, Configuration: Debug Win32 ------
1> Source.cpp
1>Source.obj : error LNK2019: unresolved external symbol _al_rest referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _al_map_rgb referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _al_create_display referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _al_destroy_display referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _al_flip_display referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _al_clear_to_color referenced in function _main
1>Source.obj : error LNK2019: unresolved external symbol _al_install_system referenced in function _main
1>c:\users\jacob\documents\visual studio 2015\Projects\Project7\Debug\Project7.exe : fatal error LNK1120: 7 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Anything helps, thanks.
Unresolved external symbol implies a compile-time linker error. When you downloaded Allegro, it will have come with a collection of resources:
includes (.h/.hpp): These are header files which define what functions exist within the library, but will not actually contain the function code themselves.
libraries (.lib): These files contain pre-compiled code and need to be linked to your project.
dlls (.dll): DLLs aren't always used when you have other library resources, however they support runtime linkage and need to be distributed with your application in order for it to run correctly.
Linker Errors
You are most likely missing a link to your libraries. In Visual studio, you can add references to libraries by right clicking on your project in the solution explorer and navigating to the linker section.
You will need to add the path to the "lib" folder in your allegro download. This can be done by adding the filepath to the additional library dependencies field.
Hope this helps!

yael mex files for windows in Matlab

I have a problem in using yael library in matlab.
Yael library has some functions like yael_ivf that has written in c.
I'm using mex command in matlab to create mex file but there are some error like this -->
Error using mex Creating library yael_ivf.lib and object
yael_ivf.exp yael_ivf.obj : error LNK2019: unresolved external
symbol _ivf_new referenced in function _mexFunction yael_ivf.obj
: error LNK2019: unresolved external symbol _ivf_delete referenced
in function _mexFunction
Please help me to mex them or if link me to Yael windows mex file.
This is yael library link: gforge.inria.fr/frs/?group_id=2151 in this page there are some links to download, for mac, for linux and windows. The Yael library for linux and mac contain mex files but unfortunately there aren't any mex file in windows link.
If you download windows yael library (third link), in matlab folder, when you run make.m, mex files must create. but there are some errors for me.

unresolved symbols after converting VS2012 Windows 8 Metro solution to VS2013 (on Windows 8.1)

I have a question, which I'm currently unable to tackle effectively since I'm still unfamiliar with Metro app development. So please bear with me :)
Long story short, I have a large, complex VS2012 Metro app managed+native solution (currently built on Windows 8) into VS2013 targeting Windows 8.1.
I imported the solution into VS2013 (hosted on Windows 8.1), and run the conversion for it and all the sub projects therein. Stuff compile, but it is with the linker that we run into problems. This is an example of the linker errors we get:
error LNK2019: unresolved external symbol __imp___beginthreadex referenced in function <blahblahblah>
error LNK2019: unresolved external symbol __imp___mbsrchr referenced in function <blahblahblah>
error LNK2019: unresolved external symbol _getenv referenced in function <blahblahblah>
error LNK2019: unresolved external symbol __imp___beginthreadex referenced in function <blahblahblah>
error LNK2019: unresolved external symbol __imp___endthreadex referenced in function <blahblahblah>
error LNK2019: unresolved external symbol __imp___mbsrchr referenced in function <blahblahblah>
error LNK2019: unresolved external symbol __imp___mbsnbicmp referenced in function <blahblahblah>
error LNK2019: unresolved external symbol __imp___dupenv_s referenced in function <blahblahblah>
The thing is that for every single symbol that is 'missing', we can see the that the declaration is present in the MS Windows header files supplied with VS2013. Inspecting the references in each sub-project shows that they are referencing the Windows 'core' libs.
Any ideas why this is happening? Thanks.
we can see the that the declaration is present in the MS Windows header files supplied with VS2013. Inspecting the references in each sub-project shows that they are referencing the Windows 'core' libs
It is going to be difficult to diagnose what went wrong with this little information, but it is pretty clear that you are looking in the completely wrong corner for this problem. The missing symbols are not Windows api functions, they are C runtime support functions. They are only used in a C++ project, you've been looking at .NET projects.
So you'll need to focus on the one project that generates these linker errors, it is a C++ project. The linker command that's issued to get it to link to the .lib that has these symbols is completely automagic so there isn't much that can go wrong. The very first thing to do is to force a complete rebuild so it won't use outdated .obj and .lib files that were left over from a previous build in VS2012. Right-click the project and choose Rebuild.
And it is worth taking a look at the .vcxproj file for this project with a text editor (like Notepad) and ensure that the conversion went properly and made the correct changes:
the ToolsVersion property must be changed from "4.0" to "12.0"
the MinimumVisualStudioVersion property must be changed from 11.0 to 12.0
two new properties are added, ApplicationType (Windows Store) and ApplicationTypeRevision (8.1)
every configuration's PlatformToolset property must be changed from v110 to v120
There is a log file in the Debug\projectname.tlog directory named link.read.1.tlog that contains diagnostics, it shows all the .lib files that the linker uses. It must contain this line:
C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 12.0\VC\LIB\STORE\VCCORLIBD.LIB
Which is the .lib file that contains these symbols.

MATLAB gives error while generating MEX file from Fortran source codes

When I try to generate the MEX file from the Fortran source code (TEINITG.F), Matlab always gives errors.After downloading the trial versions of Intel Visual Fortran 11.1 Microsoft Visual C++ 2008 SP1 linker, I used mex -setup to configure the environment. Then I tried to generate mex functions from FORTRAN Source Code (TEINITG.F).
However, when I type: mex TEINITG.F
Matlab shows link errors, like:
>>mex TEINITG.F
Creating library C:\Users\xue\AppData\Local\Temp\mex_TDkmp3\templib.x and object
C:\Users\xue\AppData\Local\Temp\mex_TDkmp3\templib.exp
TEINITG.obj : error LNK2019: unresolved external symbol _TEINIT referenced in function
_MEXFUNCTION
TEINITG.mexw32 : fatal error LNK1120: 1 unresolved externals
C:\PROGRA~2\MATLAB\R2010B~1\BIN\MEX.PL: Error: Link of 'TEINITG.mexw32' failed.
I am running MATLAB R2010b-32bit on windows-64 bit. Might that be the source of problem?
I do not know how to deal with this error. Do you have any suggestions that may fix this problem?