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

fatal error C1083: Cannot open include file: 'complex.h'

926 views
Skip to first unread message

Nick Snels

unread,
May 14, 2009, 5:06:01 AM5/14/09
to
Hi,

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

unread,
May 17, 2010, 5:37:03 AM5/17/10
to
Having the same problem. I understand that complex number support in C is only available in C99 compliant compilers, and that MVSC is NOT C99 compliant. Ofcourse this is available in the C++ libraries. However, Lcc (which is the default C compiler shipped with Matlab) claims to be C99 compliant, but also throws up this error (can't open 'complex.h'). Have tried various variants (#include <complex.h>, #include "complex.h",# include <complex>, ...) to no avail. Can anyone else shed any light on this?

Bobane

"Nick Snels" <sn...@yahoo.com> wrote in message <gugmtp$26l$1...@fred.mathworks.com>...

Yi-Yu

unread,
Aug 22, 2010, 2:59:07 AM8/22/10
to
I got the same problem.:<
Any ideas how I can fix this ?
Thanks !!

Nathan

"Bobane" <boba...@hotmail.com> wrote in message <hsr2nv$r1l$1...@fred.mathworks.com>...

Jim Rockford

unread,
Oct 1, 2010, 2:50:34 PM10/1/10
to
On Aug 22, 2:59 am, "Yi-Yu " <yc...@loni.ucla.edu> wrote:
> I got the same problem.:<
> Any ideas how I can fix this ?
> Thanks !!


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."

Walter Roberson

unread,
Oct 1, 2010, 3:05:22 PM10/1/10
to
On 10-10-01 01:50 PM, Jim Rockford wrote:

> 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.

Jim Rockford

unread,
Oct 1, 2010, 3:22:19 PM10/1/10
to
On Oct 1, 3:05 pm, Walter Roberson <rober...@hushmail.com> wrote:
> 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.

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.

Walter Roberson

unread,
Oct 1, 2010, 3:44:56 PM10/1/10
to
On 10-10-01 02:22 PM, Jim Rockford wrote:
> On Oct 1, 3:05 pm, Walter Roberson<rober...@hushmail.com> wrote:
>> 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.
>
> 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.

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.

0 new messages