I'm trying to compile C code in matlab 7.7.0 R2008b on a Vista 64 bit system using Visual Studio C++ 2008 Express edition. And I'm getting the error:
C:\PROGRA~1\MATLAB\R2008B\TOOLBOX\PACKAG~1\EMDS\SRC\cemdc.c(19) : fatal error C1083: Cannot open include file: 'complex.h': No such file or directory
If I go looking for this file in my Visual Studio include folder I can not find it. I only see a file named complex. I have already tried to rename it too complex.h, but than I get a bunch of cmath errors like the ones below:
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE\cmath(21) : error C2143: syntax error : missing '{' before ':'
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\INCLUDE\cmath(21) : error C2059: syntax error : ':'
Any ideas how I can fix this and get this code to work? Thanks.
Kind regards,
Nick
Bobane
"Nick Snels" <sn...@yahoo.com> wrote in message <gugmtp$26l$1...@fred.mathworks.com>...
Nathan
"Bobane" <boba...@hotmail.com> wrote in message <hsr2nv$r1l$1...@fred.mathworks.com>...
I had the same problem using the Visual Studio C++ 2008 compiler. I
switched to the native Matlab lcc compiler (on R2010b, 32bit windows
xp) and managed to get the emd package to compile, with the warning
messages below. It appears that the lcc compiler is smart enough to
substitute some older C data type for complex numbers, in lieu of the
C99 standard. Why do C++ compilers not recognize this data type?
What's going on here?? Anyway, it appeared to work.
Here are the warnings I got:
"C:\PROGRA~1\MATLAB\R2010B\BIN\MEX.PL: Error: Compile of
'cemdc2_fix.c' failed.
Warning: <complex.h> compiler extension not found. using ANSI C
implementation (slower) instead for the following files:
> In make_emdc at 41
In install_emd at 26
cemdc.c
cemdc_fix.c
cemdc2.c
cemdc2_fix.c
Compilation successfull.
Some codes can run faster if they are compiled with a C compiler
that handles the C99 complex data type ("complex.h"). See details
above."
> I had the same problem using the Visual Studio C++ 2008 compiler. I
> switched to the native Matlab lcc compiler (on R2010b, 32bit windows
> xp) and managed to get the emd package to compile, with the warning
> messages below. It appears that the lcc compiler is smart enough to
> substitute some older C data type for complex numbers, in lieu of the
> C99 standard. Why do C++ compilers not recognize this data type?
You are compiling C code. C++ is a different language. It is easy to write a
source file that will write out The Declaration of Independence if compiled
with a C compiler, but will write out Green Eggs And Ham if compiled with a
C++ compiler. What a C++ compiler does with C source code is not defined.
Any given compiler might have an option to compile multiple languages, and
might to some extent even be able to guess as to which language a given source
is written in. Such things are bonuses as far as the C or C++ languages are
concerned.
C++ does not use <complex.h> . The C++ header file for complex numbers is
named <complex> with *no* '.h' . Whether any dual-purpose compiler happens to
support C's <complex.h> as well as C++'s <complex> is a matter of chance.
Yes, but listening to you one might get the impression that C code
rarely compiles properly with a standard C++ compiler like
Microsoft Visual Studio. This is not remotely close to being the
case. Most C code I've needed to compile
worked just fine with a C++ compiler. In my experience it's extremely
unusual for compilation errors
of the type we're talking about to pop up. Hardly a "matter of
chance" coin flip situation like you imply. In any case, the lcc
compiler seems versatile enough to deal with this C99 standard complex
data type and substitute an equivalent.
That impression would be correct. There are some common idioms in C that are
forbidden in C++ . It is indeed rare (or at least uncommon) for C code that is
not specifically written with C++ in mind to compile with a C++ compiler.
> This is not remotely close to being the
> case. Most C code I've needed to compile
> worked just fine with a C++ compiler.
Luck, or you assumed that because an executable was produced that there was no
error. There are constructs that are defined to give different answers for C
and C++.
> In my experience it's extremely
> unusual for compilation errors
> of the type we're talking about to pop up. Hardly a "matter of
> chance" coin flip situation like you imply.
What is *not* especially uncommon is for the compilation command to not be the
name of a compiler itself, but rather the name of a "driver" program that
examines file extensions and command line options in order to determine which
compiler to use for any particular source, compiling .c files with a *C*
compiler, and compiling .cpp or .C files with a *C++* compiler. In some cases
the choice of name for the driver program determines which libraries are
automatically linked against by default. This is not the same thing as
compiling C code with a C++ compiler: this is the driver program choosing an
appropriate compiler for the code.
Based upon earlier postings in this thread, it appears that the C compiler
that Visual Studio C++ 2008 chooses does not happen to be C99 compliant.
<complex.h> is defined in C99 but was not defined in C89.