Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Error using mex: Unable to complete successfully

240 views
Skip to first unread message

Katherine Ellis

unread,
Apr 4, 2012, 11:05:17 AM4/4/12
to
Hi,

I have downloaded a program written in C, and wish to run it in Matlab.
To do this is use the mex to compile it into Matlab.

This has worked for me for the entire (academic) year. However, I tried to use it today and I got the error;

'Error using mex
Unable to complete successfully.'

along with a list of lots of errors in the code.

I have no idea what's going on. It worked fine before, but suddenly does not. I have not changed the code in any way, I even re-downloaded it in case the file had been corrupted (the code is written by Liverpool University, so is reputable source).

Please could somebody help with this problem; this is my Final Year Project at University, and the deadline is soon.

Thank you in advance.
Katherine

Steven_Lord

unread,
Apr 4, 2012, 12:49:35 PM4/4/12
to


"Katherine Ellis" <katheri...@worc.ox.ac.uk> wrote in message
news:jlhnvd$llm$1...@newscl01ah.mathworks.com...
> Hi,
>
> I have downloaded a program written in C, and wish to run it in Matlab.
> To do this is use the mex to compile it into Matlab.
>
> This has worked for me for the entire (academic) year. However, I tried to
> use it today and I got the error;
>
> 'Error using mex
> Unable to complete successfully.'
>
> along with a list of lots of errors in the code.

Post to the newsgroup the first few errors that you receive; perhaps they'll
show a pattern that suggests a cause.

--
Steve Lord
sl...@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Katherine Ellis

unread,
Apr 4, 2012, 2:15:17 PM4/4/12
to
"Steven_Lord" <sl...@mathworks.com> wrote in message <jlhu31$g74$1...@newscl01ah.mathworks.com>...
OK, here is a list of the errors (note, the file I am trying to compile is called Miguel_2D_unwrapper.cpp);

lcc preprocessor error: Miguel_2D_unwrapper.cpp:9 Could not find include file "stdafx.h"
Error Miguel_2D_unwrapper.cpp: 39 syntax error; found `PIXEL' expecting `}'
Error Miguel_2D_unwrapper.cpp: 39 skipping `PIXEL' `*' `pointer_1'
Error Miguel_2D_unwrapper.cpp: 40 syntax error; found `*' expecting `;'
Error Miguel_2D_unwrapper.cpp: 42 unrecognized declaration
Warning Miguel_2D_unwrapper.cpp: 42 empty declaration
Error Miguel_2D_unwrapper.cpp: 46 syntax error; found `*' expecting `)'
Error Miguel_2D_unwrapper.cpp: 46 skipping `*' `Pointer1' `,'
Error Miguel_2D_unwrapper.cpp: 46 missing identifier
Error Miguel_2D_unwrapper.cpp: 46 syntax error; found `int' expecting `;'
Error Miguel_2D_unwrapper.cpp: 46 missing identifier
Error Miguel_2D_unwrapper.cpp: 46 syntax error; found `int' expecting `;'
Error Miguel_2D_unwrapper.cpp: 46 syntax error; found `)' expecting `;'
Error Miguel_2D_unwrapper.cpp: 46 skipping `)' `{'
Error Miguel_2D_unwrapper.cpp: 48 illegal initialization for parameter `counter1'
Error Miguel_2D_unwrapper.cpp: 49 illegal initialization for parameter `counter2'
Error Miguel_2D_unwrapper.cpp: 50 illegal initialization for parameter `TemporalPointer'
Error Miguel_2D_unwrapper.cpp: 52 illegal initialization for parameter `Result'
Error Miguel_2D_unwrapper.cpp: 53 illegal initialization for parameter `Follower'
Error Miguel_2D_unwrapper.cpp: 53 declared parameter `Follower' is missing
Error Miguel_2D_unwrapper.cpp: 52 declared parameter `Result' is missing
Error Miguel_2D_unwrapper.cpp: 50 too many errors

Hope that helps
Katherine

dpb

unread,
Apr 4, 2012, 2:51:32 PM4/4/12
to
On 4/4/2012 1:15 PM, Katherine Ellis wrote:
> "Steven_Lord" <sl...@mathworks.com> wrote in message
...

>> Post to the newsgroup the first few errors that you receive; perhaps
>> they'll show a pattern that suggests a cause.
...

> OK, here is a list of the errors (note, the file I am trying to compile
> is called Miguel_2D_unwrapper.cpp);
>
> lcc preprocessor error: Miguel_2D_unwrapper.cpp:9 Could not find include
> file "stdafx.h"...

It would seem to help if you would actually read the errors and heed them.

There's a missing header file called "stdafx.h" that undoubtedly has the
declarations that being missing cause most if not all of the remaining
errors.

Either locate this file from wherever you got the other or fix the path
statements/include environment variable to allow the file to be found by
the compiler; whatever is the appropriate action depending on whether
you have the file at hand or not...

--

Katherine Ellis

unread,
Apr 4, 2012, 4:35:17 PM4/4/12
to
dpb <no...@non.net> wrote in message <jli57s$7uq$1...@speranza.aioe.org>...
OK, but there's no need to be so rude about it; this is way beyond my expertise and I didn't know what the errors meant.

I am now no longer getting the error lcc preprocessor error: Miguel_2D_unwrapper.cpp:9 Could not find include file "stdafx.h"...
just the other syntax errors.

Any ideas why?

Thank you

dpb

unread,
Apr 4, 2012, 6:49:47 PM4/4/12
to
"Rude" has nothing to do with it; the first error is a straightforward
statement of a fact the compiler found.

As far as the rest, it's impossible to tell w/o a revised set of errors
given w/ the previously missing file available because there's no reason
to think the same errors are existant in it's present as would be w/o it.

--

Steven_Lord

unread,
Apr 5, 2012, 9:21:46 AM4/5/12
to


"Katherine Ellis" <katheri...@worc.ox.ac.uk> wrote in message
news:jliba5$bpn$1...@newscl01ah.mathworks.com...
> dpb <no...@non.net> wrote in message <jli57s$7uq$1...@speranza.aioe.org>...
>> On 4/4/2012 1:15 PM, Katherine Ellis wrote:
>> > "Steven_Lord" <sl...@mathworks.com> wrote in message

*snip*

> I am now no longer getting the error lcc preprocessor error:
> Miguel_2D_unwrapper.cpp:9 Could not find include file "stdafx.h"...
> just the other syntax errors.
>
> Any ideas why?

Are you certain that they're the same exact errors? Debugging compiler
issues like this can be somewhat of an iterative process; fix problem,
recompile, find new problem, repeat.

In addition to showing the errors, please show a small segment of the code
referred to in the error message, say two commands before and two commands
after. Sometimes a compiler will report a problem on line 17, say, that's
actually caused by a problem (missing semicolons, in particular) on line 16
or 15.

Katherine Ellis

unread,
Apr 5, 2012, 10:46:17 AM4/5/12
to
"Steven_Lord" <sl...@mathworks.com> wrote in message <jlk69a$5hc$1...@newscl01ah.mathworks.com>...
Hi,
Thanks for your help so far. I think the problem is the compiler. When I have done the mex setup, I have been using the compiler which is included with Matlab (Lcc-win32 C 2.4.). But I just downloaded Microsoft Software Development Kit (SDK) 7.1 and used the compiler provided in that, and it seems to work fine now.
Perhaps there is an issue/bug with the Matlab compiler? (This might make sense as I had to reinstall Matlab recently, and it has been since then that I have been having these problems).
Thanks
Katherine

dpb

unread,
Apr 5, 2012, 11:01:37 AM4/5/12
to
On 4/5/2012 9:46 AM, Katherine Ellis wrote:
...

> Hi, Thanks for your help so far. I think the problem is the compiler.
> When I have done the mex setup, I have been using the compiler which is
> included with Matlab (Lcc-win32 C 2.4.). But I just downloaded Microsoft
> Software Development Kit (SDK) 7.1 and used the compiler provided in
> that, and it seems to work fine now.
> Perhaps there is an issue/bug with the Matlab compiler? (This might make
> sense as I had to reinstall Matlab recently, and it has been since then
> that I have been having these problems).

It is an "issue" but it is not a "bug"

MS is notorious for using extensions and other proprietary features in
their compilers and other software products that do not follow
established Standards.

Undoubtedly the code you have downloaded was developed on and for and
uses some of these specific MS extensions.

That other compilers don't implement all of these features doesn't make
them buggy, only incompatible. For the inexperienced these may
superficially look to be the same thing but there's a big difference in
the conceputalization.

Your choices are to continue to use the MS-specific tools or convert the
code to a more platform/OS-independent form. If there is no need for
the code except on a supported OS, then you may as well stick w/ using
the MS compilers (just recognizing the need for the specific toolset).

--

Kent

unread,
Apr 5, 2012, 11:02:17 AM4/5/12
to
"Katherine Ellis" wrote in message <jlkb7p$q25$1...@newscl01ah.mathworks.com>...
Katherine,

What likely happened is that when you reinstalled Matlab it defaulted back to the provided compiler, which won't know about stdafx.h, which is a standard pre-compiled header file used only by visual studio I believe. Re-running mexsetup to use the Microsoft compiler fixed the problem.

Kent

Steven_Lord

unread,
Apr 5, 2012, 11:07:16 AM4/5/12
to


"Katherine Ellis" <katheri...@worc.ox.ac.uk> wrote in message
news:jlkb7p$q25$1...@newscl01ah.mathworks.com...
> "Steven_Lord" <sl...@mathworks.com> wrote in message
> <jlk69a$5hc$1...@newscl01ah.mathworks.com>...

*snip*

> Hi, Thanks for your help so far. I think the problem is the compiler. When
> I have done the mex setup, I have been using the compiler which is
> included with Matlab (Lcc-win32 C 2.4.). But I just downloaded Microsoft
> Software Development Kit (SDK) 7.1 and used the compiler provided in that,
> and it seems to work fine now.
> Perhaps there is an issue/bug with the Matlab compiler? (This might make
> sense as I had to reinstall Matlab recently, and it has been since then
> that I have been having these problems).

Ahh ... I missed a clue here. Your code is written in C++, yes? I remember
you mentioning that the errors were being reported in a .cpp file.

LCC is a _C_ compiler.

http://en.wikipedia.org/wiki/LCC_%28compiler%29

Using a C compiler to compile C++ code _may_ work but probably will not.

dpb

unread,
Apr 5, 2012, 2:15:06 PM4/5/12
to
On 4/5/2012 10:07 AM, Steven_Lord wrote:
...

> Ahh ... I missed a clue here. Your code is written in C++, yes? I
> remember you mentioning that the errors were being reported in a .cpp file.
>
> LCC is a _C_ compiler.
>
> http://en.wikipedia.org/wiki/LCC_%28compiler%29
>
> Using a C compiler to compile C++ code _may_ work but probably will not.

Oh, yeah, I saw the extension but didn't think to comment on that
aspect, either, Steven, as well as the MS-specific portion of the code
being dependent on VS.

--

joybcube

unread,
Feb 12, 2014, 12:38:21 PM2/12/14
to
Hi Katherine,

I am trying to compile a C++ code with mex but am unable to compile it successfully . Reading some related comments, I installed both Microsoft Visual C++ 2010 Express and Windows Software Development Kit (SDK) 7.1 but still it's giving this error:

>>>> facePart.cpp(5) : fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory

Can you help me figure out the problem please...?

I am using a 64-bit Windows Platform with matlab version 2011a...

By the way, after typing mex -setup, it gives me something like this:
Please choose your compiler for building MEX-files:

Would you like mex to locate installed compilers [y]/n? y

Select a compiler:
[1] Microsoft Visual C++ 2010 Express in C:\Program Files (x86)\Microsoft Visual Studio 10.0

[0] None

Compiler: 1

Please verify your choices:

Compiler: Microsoft Visual C++ 2010 Express
Location: C:\Program Files (x86)\Microsoft Visual Studio 10.0

Are these correct [y]/n? y

***************************************************************************
Warning: MEX-files generated using Microsoft Visual C++ 2010 require
that Microsoft Visual Studio 2010 run-time libraries be
available on the computer they are run on.
If you plan to redistribute your MEX-files to other MATLAB
users, be sure that they have the run-time libraries.
***************************************************************************

Trying to update options file: C:\Users\JOY\AppData\Roaming\MathWorks\MATLAB\R2011a\mexopts.bat
From template: C:\PROGRA~1\MATLAB\R2011a\bin\win64\mexopts\msvc100freeopts.bat

Done . . .

**************************************************************************
Warning: The MATLAB C and Fortran API has changed to support MATLAB
variables with more than 2^32-1 elements. In the near future
you will be required to update your code to utilize the new
API. You can find more information about this at:
http://www.mathworks.com/support/solutions/en/data/1-5C27B9/?solution=1-5C27B9
Building with the -largeArrayDims option enables the new API.
**************************************************************************

looking forward to hear from you guys...
thanks.

-Joy



0 new messages