I am trying to compile some MATLAB MEX files from C++ source. The files I am trying to compile can be found here; I am using Windows XP on a 32-bit system, MATLAB 2012a and have installed the Microsoft Windows SDK v7.1 to use as my compiler.
MATLAB outputs the following error if I try to compile:
>> mex -O -largeArrayDims osc_free_address.c
osc_free_address.c
osc_free_address.c(1) : error C2059: syntax error : '<'
osc_free_address.c(37) : error C2015: too many characters in constant
osc_free_address.c(38) : error C2059: syntax error : '<'
osc_free_address.c(39) : error C2015: too many characters in constant
osc_free_address.c(39) : error C2015: too many characters in constant
osc_free_address.c(39) : error C2015: too many characters in constant
osc_free_address.c(41) : error C2018: unknown character '0x40'
osc_free_address.c(43) : error C2015: too many characters in constant
osc_free_address.c(44) : error C2015: too many characters in constant
osc_free_address.c(44) : error C2015: too many characters in constant
osc_free_address.c(44) : error C2015: too many characters in constant
osc_free_address.c(44) : error C2015: too many characters in constant
osc_free_address.c(46) : error C2059: syntax error : '<'
osc_free_address.c(82) : fatal error C1021: invalid preprocessor command 'page'
C:\PROGRA~1\MATLAB\R2012A\BIN\MEX.PL: Error: Compile of 'osc_free_address.c' failed.
Error using mex (line 206)
Unable to complete successfully.
I have used mex -setup to setup my compiler with Microsoft Windows SDK v7.1. Interestingly, although I have them installed on my system, MATLAB doesn't see MS Visual Studio C++ 2008 or 2010. I have also tried compiling with the Lcc-win32 C 2.4.1 compiler (which is recognised by MATLAB), to the same effect as shown above.
I understand that this particular set of C++ source files might require something called liblo to compile (I'm not sure whether this is a requirement at compile-time or run-time); as far as I'm aware I have installed these correctly, but there's a possibility that the problem might lie here too.
Any help would be greatly appreciated.
Try renaming your .c files to .cpp and re-compile
>> mex -largeArrayDims -O osc_free_address.cpp
Moreover, why don't you try the build m file that comes with the package
(as suggested in this question)?
Have you downloaded and compiled liblo? you might need to add the include path and library path for it in the mex command?
>> mex -largeArrayDims -O -I<liblo include path> -L<liblo lib path> -llo osc_free_address.cpp
Related
I have been using VS 2008, and have installed VS 2015 side by side on the same computer. I have projects compiled in VS 20015 from another computer that compile just fine. But when I open those projects and try to compile them in the new VS 2015 on this computer they will not compile. In fact, even creating the simplest "Hello world" application will not compile.
I get errors on standard VS header files. For example, it throws errors and warnings on Windows.h like:
Warning C4067 unexpected tokens following preprocessor directive -
expected a newline windows.h
Error C2061 syntax error: identifier 'LPCSTR'
Error C2061 syntax
error: identifier 'BYTE'
I can't figure out why this is happening. Anyone have an idea?
I am trying to load a C++ API (for the BB60C radio at SignalHound.com) into Matlab using loadlibrary() but it is only working in 32-bit Matlab (R2014a). The zip file here contains the bb_api.h header file and has both a 32-bit and 64-bit bb_api.dll in their respective folder. To run it, I copy the correct .dll into the folder with bb_api.h and call loadlibrary('bb_api','bb_api.h'). While this works for the 32-bit version, when I use the 64-bit .dll in 64-bit Matlab, I get the following error:
Error using loadlibrary (line 422)
Building bb_api_thunk_pcwin64 failed. Compiler output is:
cl -I"C:\Program Files\MATLAB\R2014a\extern\include" /W3 /nologo /D_CRT_SECURE_NO_DEPRECATE
/D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 -I"C:\Program Files\MATLAB\R2014a\extern\include" -I"C:\Program
Files\MATLAB\R2014a\simulink\include" -I"C:\Users\mimhof\Documents\GitHub\SDR\Matlab"
-I"C:\Users\mimhof\Documents\GitHub\SDR\Matlab" "bb_api_thunk_pcwin64.c" -LD -Fe"bb_api_thunk_pcwin64.dll"
bb_api_thunk_pcwin64.c
C:\Users\mimhof\Documents\GitHub\SDR\Matlab\bb_api.h(202) : error C2061: syntax error : identifier 'bbOpenDevice'
C:\Users\mimhof\Documents\GitHub\SDR\Matlab\bb_api.h(202) : error C2059: syntax error : ';'
C:\Users\mimhof\Documents\GitHub\SDR\Matlab\bb_api.h(202) : error C2059: syntax error : 'type'
C:\Users\mimhof\Documents\GitHub\SDR\Matlab\bb_api.h(203) : error C2061: syntax error : identifier 'bbCloseDevice'
C:\Users\mimhof\Documents\GitHub\SDR\Matlab\bb_api.h(203) : error C2059: syntax error : ';'
C:\Users\mimhof\Documents\GitHub\SDR\Matlab\bb_api.h(203) : error C2059: syntax error : 'type'`
and so on for all the methods available in the API. What would cause this error to occur in 64-bit and not 32-bit?
Thanks!
You talk about using C++, but your file is named .c, which triggers compilation using the C language rules. The Microsoft compiler's C support is pretty outdated, and it's likely that is the source of your problems. You may want to use C++ instead.
Beyond that, take a close look at the line where the error occurs, just as if you were fixing compile errors in your own code.
The ***_thunk.c file is auto-generated by a perl script shipped with matlab, and is the source of many similar errors.
This fact (the auto generated thunk source is in c) is the source of many documented seemingly weird loadlibrary limitations and many more undocumented ones.
My solution when being hit by a very similar issue was to hijack this auto-generated file, rename it to cpp and build my own cpp version of the thunk. This required some hacking, as this file lifespan is a fraction of a second. Full details are here.
I have been trying recently to get UVC (USB Video Class) extension unit up and running.I did make some progress (by getting vidcap_i.c by a lead from a message from another forum),but I have not been able to go through due to compilation errors and I hope I could get some help here for the subject.
I have created all the necessary files ,which I was guided by the sample at Microsoft site,except the sample application.
Their content is the same as at the UVC sample link.
*Note:I got a little confused by the line that says "Copy Extend.def from the WIA extend sample and edit it. Uvcxuplugn.def should contain".I hope I got it correctly - I have copied the extend.def file from WDK samples directory to
c:\xu directory ,edited the file ,added the necessary content and saved it as Uvcuplugn.def file.
After building using the Build environment ,this is the output of the compilation :
C:\xu>Build -cZg
BUILD: Compile and Link for AMD64
BUILD: Start time:
BUILD: Examining c:\xu directory for files to compile.
c:\xu Invalidating OACR warning log for 'root:amd64chk'
BUILD: Building generated files in c:\xu directory
Configuring OACR for 'root:amd64chk' -
Running MIDL on - interface.idl
BUILD: Compiling c:\xu directory
Compiling - interface_i.c
Compiling - vidcap_i.c
Compiling - uvcxuplgn.cpp
1>errors in directory c:\xu
1>c:\xu\xuproxy.h(69) : error C2017: illegal escape sequence
1>c:\xu\xuproxy.h(71) : error C2059: syntax error : '__uuidof'
1>c:\xu\xuproxy.h(71) : error C2017: illegal escape sequence
1>c:\xu\xuproxy.h(71) : error C2332: 'struct' : missing tag name
1>c:\xu\xuproxy.h(71) : error C2011: '' : 'enum' type redefinition
1>c:\xu\uvcxuplgn.cpp(7) : error C2143: syntax error : missing ';' before '{'
1>c:\xu\uvcxuplgn.cpp(7) : error C2447: '{' : missing function header (old-style
formal list?)
1>c:\xu\uvcxuplgn.cpp(31) : error C2065: 'ObjectMap' : undeclared identifier
Compiling - stdafx.cpp
Compiling - xuproxy.cpp
Building Library - objchk_win7_amd64\amd64\uvcxuplgn.lib
1>link : error LNK1181: cannot open input file 'c:\xu\objchk_win7_amd64\amd64\uv
cxuplgn.obj'
BUILD: Compile errors: not linking c:\xu directory
BUILD: Finish time:
BUILD: Done
12 files compiled - 1 Warning - 8 Errors
1 library built - 1 Error
I get the same errors no matter what the target is (x86,x64,ia64)
Now,let's review errors one by one ,starting from the last :
LNK1181->No idea about that error.I have done clean ups of the build and that did not help
at all.But this is probably the easiest error to resolve,hope you would be able to give me
a lead on the subject.
uvcxuplgn.cpp,Line 7 ,the problematic syntax is :BEGIN_OBJECT_MAP(ObjectMap).
According to Microsoft's documentation (http://msdn.microsoft.com/en-us/library/10fb0d3e(v=vs.90).aspx) , this directive is defined at atlcom.h,which is included
in the file ,so I am really confused about the cause of this error.
The last errors relate to last 5 lines of extension unit proxy header file (cannot post code here due to errors-check this page (http://msdn.microsoft.com/en-us/library/windows/hardware/ff568134(v=vs.85).aspx)
Again,no idea ,why it shouldn't compile.Hope I could get some lead on the subject
Sorry for the long post,hope you could help me (and probably many others) who struggle with this Windows UVC extension unit subject
First, you always have to look at the first error that happens. The others are often following errors. So just delete the wrong escape sequence () in line 69 and in line 71 in xuproxy.h.
The linking error only happens, because the compiler couldnt compile the .cpp files earlier, so the object file is missing.
I am having trouble writing a MEX file in MATLAB that can perform a simple linear operation such as taking the inverse of a matrix. I have successfully managed to take the inverse of a matrix using Visual Studio 2010 and have successfully created a MEX file hence the only thing I am having trouble is getting these two concepts together. I have tried to compile a MEX example code that I got from the MathWorks site but with no luck.
Here is what I have tried,
Saved the file (renamed it) I got from MathWorks as .c extension and then tried to compile it in MATLAB got:
Creating library C:\Users\CIT\AppData\Local\Temp\mex_bKHjrl\templib.x
and object C:\Users\CIT\AppData\Local\Temp\mex_bKHjrl\templib.exp
eko1.obj : error LNK2019: unresolved external symbol dgesv referenced
in function mexFunction eko1.mexw64 : fatal error LNK1120: 1
unresolved externals
Also I tried to compile it as a .cpp file however an error occurred because it didnt recognize the memcpy function.
Since these didn't work I wrote my own program that used the subroutines dgetrf and dgetri from the LAPACK library however an error occured:
c:\users\cit\documents\matlab\f2c.h(16) : error C2371: 'complex' :
redefinition; different basic types
C:\Program Files\MATLAB\R2011b\extern\include\lapack.h(39) : see declaration of 'complex' c:\users\cit\documents\matlab\f2c.h(17)
: error C2371: 'doublecomplex' : redefinition; different basic types
C:\Program Files\MATLAB\R2011b\extern\include\lapack.h(40) : see declaration of 'doublecomplex' eko2.cpp(29) : error C2057:
expected constant expression eko2.cpp(29) : error C2466: cannot
allocate an array of constant size 0 eko2.cpp(29) : error C2133:
'ipiv' : unknown size eko2.cpp(33) : error C2664: 'dgetrf' : cannot
convert parameter 1 from 'integer *' to 'ptrdiff_t *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast eko2.cpp(34) :
error C2664: 'dgetri' : cannot convert parameter 1 from 'integer *' to
'ptrdiff_t *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Any help you guys give me would be extremely appreciated
Thanks in advance.
Without any code to see what you've tried, it's hard to tell, but... in order to properly compile a mex file in matlab that depends on other libraries, you need to specify those libraries in the compile command. Use mex filename.c -v -l*libraryname*.lib. The -l switch indicates to the compiler that you are specifying a library that you want to include. If this library is not found, I would include the full path to the library in the command. I hope that provides you with some assistance. Using this methodology has been successful for me.
I have compiled the NTL inifite precision integer arithmetic library for c++, using Microsoft Visual Studio 2008. I did as explained, on this site, using the Visual Studio interface, rather than from the command prompt. Actually I would rather do it from the command prompt, but I was not sure how to.
Anyhow, I got the library compiled, and I now want to compile a program using the library, from the command prompt. The program I am trying to compile, has been tested on a linux system, where I compile it with the following
c++ -I/appl/htopopt/Linux_x86_64/NTL-5.4.2/include mpqs.cpp main.cpp -o main -L/appl/htopopt/Linux_x86_64/NTL-5.4.2/lib -lntl -L/appl/htopopt/Linux_x86_64/gmp-4.2.1/lib -lgmp -lm
Nevermind the gmp stuff, I dont have that installed on Windows. It is purely an optional thing that will make the NTL run faster. Anyhow, this works fine on linux. Now on Windows I write the following
cl /EHsc /I D:\Downloads\WinNTL-5_5_2\include mpqs.cpp main.cpp /link /LIBPATH:"D:\Documents\Visual Studio 2008\Projects\ntl\Debug"
But this results in the following errors:
mpqs.cpp
mpqs.cpp(38) : error C2039: 'find_smooth_vals' : is not a member of 'QS'
d:\desktop\qs\mpqs.h(12) : see declaration of 'QS'
mpqs.cpp(41) : error C2065: 'M' : undeclared identifier
mpqs.cpp(41) : error C2065: 'n' : undeclared identifier
mpqs.cpp(42) : error C2065: 'sieve_table' : undeclared identifier
mpqs.cpp(42) : error C2228: left of '.size' must have class/struct/union
type is ''unknown-type''
mpqs.cpp(43) : error C2065: 'sieve_table' : undeclared identifier
mpqs.cpp(44) : error C2065: 'qx_table' : undeclared identifier
mpqs.cpp(44) : error C3861: 'test_smoothness': identifier not found
mpqs.cpp(45) : error C2065: 'smooth_indices' : undeclared identifier
mpqs.cpp(45) : error C2228: left of '.push_back' must have class/struct/union
type is ''unknown-type''
main.cpp
Generating Code...
It is as if, my mpqs.h file is not included into the compilation process? Also I dont understand why it complains about .push_back() for a vector type?
Help is much appreciated!
mpqs.h is definitely being included as the output asks you to refer to it.
Seeing as MPQS.h does not appear to be included in the NTL library ... did you write it? If so can you post the code up?
Also, shouldn't you included the library file somewhere on your build?
Edit: There is no function find_smooth_values so why should you expect MSVC to find it? I'm not sure why that compiles under GCC but its obviously missing. I'm guessing that the other errors are caused because of this one. The errors are telling you things. You should listen to them.
push_back is failing because it doesn't know what the type you are trying to push_back into is. This again is probably caused by the fact that find_smooth_values doesn't exist. Try adding the function prototype into the QS class. This may well fix all your problems.
As for the library it won't get to using the library until the compilation succeeds. So don't worry about that just now. Get in there and fix the errors that MSVC is reporting!