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

Compile MEX with C99 comments, Unbuntu

288 views
Skip to first unread message

Jan Simon

unread,
Mar 26, 2010, 3:42:05 PM3/26/10
to
Dear readers!

Unfortuantely I cannot test it by my own, because I stuck on a Windows-machine. I thought this command would instruct the GCC compiler to accept the C99 comment style using "//":
mex -O CFLAGS="\$CFLAGS -std=C99" Shuffle.c
It is not a problem of the parsing - same effects for:
me(' -O', 'CFLAGS="\$CFLAGS -std=C99"', 'Shuffle.c')
(double quotes - char(34) - before \ and after 99)

On a 64 bit Linux machine using 2010a and GCC 4.4.1 this yields to the message:
cc1: error: unrecognized command line option "-std=C99"

In addition the MEX command suggests:
Warning: You are using gcc version "4.4.1-4ubuntu9)". The version
currently supported with MEX is "4.2.3".

While I've never seen problems to use the C99 (Or C++) comment style on Windows machines, it seems like the GCC is more sensitive. Can this be solved by another flag for the compiler? Lower case "c99" ?!
Is the C99 style still too fresh ?!

Thanks, Jan

Oliver Woodford

unread,
Mar 26, 2010, 9:25:04 PM3/26/10
to
"Jan Simon" <matlab.T...@nMINUSsimon.de> wrote in message <hoj2mc$8bn$1...@fred.mathworks.com>...

Jan, I struggled with this problem for a while. In the end I could find no command line flag that would stop the error, so I removed the -ansi flag from my mexopts.sh file.

If anyone does come up with a way to over-ride this flag from the matlab command line, and allow C++ style comments, then I'd also love to hear about it.

Oliver

James Tursa

unread,
Mar 26, 2010, 9:33:03 PM3/26/10
to
"Oliver Woodford" <o.j.woo...@cantab.net> wrote in message <hojmpg$btv$1...@fred.mathworks.com>...

I second that motion.

James Tursa

Jan Simon

unread,
Mar 27, 2010, 9:02:06 PM3/27/10
to
Dear Oliver!

> > mex -O CFLAGS="\$CFLAGS -std=c99" Shuffle.c

> Jan, I struggled with this problem for a while. In the end I could find no command line flag that would stop the error, so I removed the -ansi flag from my mexopts.sh file.

As far as I understood "-ansi" is documented to be "-std=c89", so this *must* conflict with "-std=c99". This means, that the "-ansi" should be removed from the mexopts if the user does not want to restrict the C-code to a 20 year old standard.

Google found this, but I cannot try it (no Liniux currently):
mex -O CFLAGS="\$CFLAGS -Wp,-lang-c-c++-comments" Shuffle.c

Kind regards, Jan

Oliver Woodford

unread,
Mar 28, 2010, 5:51:06 AM3/28/10
to
"Jan Simon" wrote:
> As far as I understood "-ansi" is documented to be "-std=c89", so this *must* conflict with "-std=c99". This means, that the "-ansi" should be removed from the mexopts if the user does not want to restrict the C-code to a 20 year old standard.

I agree there is a conflict. The question is how is this conflict resolved. What I wondered is if there was any option that would over-ride (i.e. take precedence over) the default behaviour of -ansi compilation. I'm looking for a solution that doesn't require people I give my code to to edit their mexopts file.

> Google found this, but I cannot try it (no Liniux currently):
> mex -O CFLAGS="\$CFLAGS -Wp,-lang-c-c++-comments" Shuffle.c

I think I've tried that, but I'll try it again.

Regards,
Oliver

Jan Simon

unread,
Mar 28, 2010, 11:14:07 AM3/28/10
to
Dear Oliver!

> > As far as I understood "-ansi" is documented to be "-std=c89", so this *must* conflict with "-std=c99". This means, that the "-ansi" should be removed from the mexopts if the user does not want to restrict the C-code to a 20 year old standard.
>
> I agree there is a conflict. The question is how is this conflict resolved.

If the mexopts file defines a crucial flag, which let the compiler fail for modern coding style, the mexopts file is corrupted. So it is a job for TWM to remove the -ansi flag.

The longer I gaze to the problem, the more ridiculous it looks: The comment style let the compiler fail, although the comments are ignored at all by definition!

I've inspected the function mex.m to find out, in which order the flags are forwarded to the compiler. To my surprise, the M-function mex calls a Perl function, which parses (not calls!) a BAT file (on a Win-PC) "mexopts.bat", which was created by another Perl function.
This is pure obfuscation. It must be possible to simplify this drastically and make it much easier for users to toggle an -ansi or -std=c99 flag!

Deeply impressed, Jan

Oliver Woodford

unread,
Mar 29, 2010, 10:47:08 AM3/29/10
to
"Jan Simon" wrote:
> Google found this, but I cannot try it (no Liniux currently):
> mex -O CFLAGS="\$CFLAGS -Wp,-lang-c-c++-comments" Shuffle.c

I can confirm this doesn't work for me (MATLAB R2009b, Ubuntu 9.10 64-bit, gcc 4.4).

> The longer I gaze to the problem, the more ridiculous it looks: The comment style let the compiler fail, although the comments are ignored at all by definition!
>
> I've inspected the function mex.m to find out, in which order the flags are forwarded to the compiler. To my surprise, the M-function mex calls a Perl function, which parses (not calls!) a BAT file (on a Win-PC) "mexopts.bat", which was created by another Perl function.
> This is pure obfuscation. It must be possible to simplify this drastically and make it much easier for users to toggle an -ansi or -std=c99 flag!

It's far from optimal, and could definitely be improved.

Oliver

ubuntu21 T

unread,
May 13, 2010, 3:08:04 PM5/13/10
to
"Jan Simon" <matlab.T...@nMINUSsimon.de> wrote in message ....

> On a 64 bit Linux machine using 2010a and GCC 4.4.1 this yields to the message:
> cc1: error: unrecognized command line option "-std=C99"
>
> In addition the MEX command suggests:
> Warning: You are using gcc version "4.4.1-4ubuntu9)". The version
> currently supported with MEX is "4.2.3".

So why don't you just install any gcc version that is supported by matlab, just as indicated in the last line ?!

The following solution works well on my Ubuntu 10.04 x86 (32bit), tested on both Matlab R2010a and R2008b (the linux versions) + gcc-4.1

Step1) one has to uncomment "multiverse" and "universe" repositories in /etc/apt/sources.list by removing the # sign before each repo, so that we may gain acces to some needed software (like gcc4.1):
$sudo vi /etc/apt/sources.list <- and there remove # before all "multiverse" and "universe" repos
$sudo apt-get update

Step2) Since apparently gcc4.2 is not offered by default (or at least at this date), no problem, just go for gcc4.1 which is highly robust to do the job:
$sudo apt-get install gcc-4.1 gcc-4.1-multilib libstdc++6-4.1-dev

Step3) The trick is that by actually installing gcc-4.1, the install procedure will not also change the default symbolic link from /usr/bin/gcc -> /usr/bin/gcc-4.4 , so we will have to do it manually:
$sudo cd /usr/bin/
$sudo ln -s gcc-4.1 gcc
And now just verify the link was properly done:
$sudo ls -la|grep gcc
And one should get something like this (copy-pasted from my console)
lrwxrwxrwx 1 root root 7 2010-05-09 14:59 gcc -> gcc-4.1

That's all. For me it works all very well.
Good luck.

Dipankar

unread,
Jun 2, 2011, 5:08:04 PM6/2/11
to
"ubuntu21 T" wrote in message <hshimk$ro3$1...@fred.mathworks.com>...

> "Jan Simon" <matlab.T...@nMINUSsimon.de> wrote in message ....
> > On a 64 bit Linux machine using 2010a and GCC 4.4.1 this yields to the message:
> > cc1: error: unrecognized command line option "-std=C99"
> >
> > In addition the MEX command suggests:
> > Warning: You are using gcc version "4.4.1-4ubuntu9)". The version
> > currently supported with MEX is "4.2.3".
>
> So why don't you just install any gcc version that is supported by matlab, just as indicated in the last line ?!
>
> The following solution works well on my Ubuntu 10.04 x86 (32bit), tested on both Matlab R2010a and R2008b (the linux versions) + gcc-4.1
>
> Step1) one has to uncomment "multiverse" and "universe" repositories in /etc/apt/sources.list by removing the # sign before each repo, so that we may gain acces to some needed software (like gcc4.1):
> $sudo vi /etc/apt/sources.list <- and there remove # before all "multiverse" and "universe" repos
> $sudo apt-get update

How to compile fortran codes in such situation ....????

Jan Simon

unread,
Jun 6, 2011, 7:04:04 AM6/6/11
to
Dear Dipankar,

> How to compile fortran codes in such situation ....????

Which situation? C++ style comments are not a usualy problem for FORTRAN compilers, are they?

Kind regards, Jan

0 new messages