🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.soft-sys.matlab
2 messages
2 total messages Started by Shing-Fat Fred Ma Mon, 13 Jan 2003 08:07
C++ & matlab engine, gcc versus SUNWspro cc
#207
Author: Shing-Fat Fred Ma
Date: Mon, 13 Jan 2003 08:07
43 lines
2350 bytes
Hello,

I know I can call the matlab engine from C/C++
using:

    gcc -o engdemo \
    -I/opt/matlab13/extern/include \
    engdemo.c \
    -L /opt/matlab13/extern/lib/sol2 \
    -leng /opt/matlab13/bin/sol2 -lmx

But that's really a mouthful.  I'd rather use the
mex script, and specify my own options.  I
compared engopt.sh parameters for linux/gcc
and solaris/SUNspro-cc.  I'll be using specifications
from both parameter sets, since I'm using gcc on
solaris.  Some of the different parameters are easy
to resolve, since they don't necessarily have a
counter part.  The hard differences to resolve are
the -D<NAME>, since they define stuff that is
meant to be recognized inside the source code
(somewhere).

For example, linux/gcc parameters include
-D_GNU_SOURCE in the compile flags,
while the SUNWspro-cc parameters include
-D__EXTENSIONS__ .   Should I include
any/both of these when using gcc on solaris?

What about the linux/gcc -ansi compile flag?
It seems that the SUNWspro-cc counterpart is
one of -Xa, -Xc, -Xs, or -Xt.  But none of
these show up in the SUNWspro-cc compile flags.

Thanks for any wisdom about this.

Fred

-- 
Fred Ma, fma@doe.carleton.ca
Carleton University, Dept. of Electronics
1125 Colonel By Drive, Ottawa, Ontario
Canada, K1S 5B6
Re: C++ & matlab engine, gcc versus SUNWspro cc
#208
Author: Shing-Fat Fred Ma
Date: Mon, 13 Jan 2003 10:38
151 lines
6055 bytes
Shing-Fat Fred Ma wrote:

> Hello,
>
> I know I can call the matlab engine from C/C++
> using:
>
>    gcc -o engdemo \
>    -I/opt/matlab13/extern/include \
>    engdemo.c \
>    -L /opt/matlab13/extern/lib/sol2 \
>    -leng -lmx
>
> But that's really a mouthful.  I'd rather use the
> mex script, and specify my own options.  I
> compared engopt.sh parameters for linux/gcc
> and solaris/SUNspro-cc.  I'll be using specifications
> from both parameter sets, since I'm using gcc on
> solaris.  Some of the different parameters are easy
> to resolve, since they don't necessarily have a
> counter part.  The hard differences to resolve are
> the -D<NAME>, since they define stuff that is
> meant to be recognized inside the source code
> (somewhere).
>
> For example, linux/gcc parameters include
> -D_GNU_SOURCE in the compile flags,
> while the SUNWspro-cc parameters include
> -D__EXTENSIONS__ .   Should I include
> any/both of these when using gcc on solaris?
>
> What about the linux/gcc -ansi compile flag?
> It seems that the SUNWspro-cc counterpart is
> one of -Xa, -Xc, -Xs, or -Xt.  But none of
> these show up in the SUNWspro-cc compile flags.
>
> Thanks for any wisdom about this.
>
> Fred

OK, I tried to guess my way to the right set
of mex parameters.  First, I should clarify that
I'm using release 13 on solaris 8.  From examining
the linux/gcc and solaris(sol2) parameters in
engopts.sh, I cobbled up the following replacement
code for using gcc with sol2:

> #           cc -V
> #           WorkShop Compilers 5.0 98/12/15 C 5.0
>             CC='gcc'
>             CFLAGS="$MFLAGS -D__EXTENSIONS__"
> #           CFLAGS="$MFLAGS"
>             CLIBS="$MLIBS -lm"
>             COPTIMFLAGS='-O -DNDEBUG'
>             CDEBUGFLAGS='-g'
> #
> #           f77 -V
> #           WorkShop Compilers 5.0 99/09/16 FORTRAN 77 5.0 patch 107596-03
>             FC='f77'
>             FFLAGS="$MFLAGS -dalign"
>             FLIBS="$MLIBS -lm"
>             FOPTIMFLAGS='-O'
>             FDEBUGFLAGS='-g'
> #
>             LD="$COMPILER"
>             LDFLAGS=''
>             LDOPTIMFLAGS='-O'
>             LDDEBUGFLAGS='-g'
> #
>             POSTLINK_CMDS=':'


I kept the -D__EXTENSIONS__ because I couldn't
find it in any source code that would be affected by
an equivalent

    #define __EXTENSIONS__

I did a recursive grep for __EXTENSIONS__ from the
matlab root directory, and it only showed up in binary
files.

The above parameters work with a normal C file
(engopt.c).  However, if I rename engopt.c to engopt.C
(capital C suffix) to simulate a c++ file, the mex command
gives me

> $$> mex -v -f /home/fma/matlab/myengopts.sh engdemo.C
> ----------------------------------------------------------------
> -> options file specified on command line:
>    FILE = /home/fma/matlab/myengopts.sh
> ----------------------------------------------------------------
> ->    MATLAB                = /opt/matlab13
> ->    CC                    = gcc
> ->    CC flags:
>          CFLAGS             = -I/opt/matlab13/extern/include 
> -D__EXTENSIONS__
>          CDEBUGFLAGS        = -g
>          COPTIMFLAGS        = -O -DNDEBUG
>          CLIBS              = -L/opt/matlab13/extern/lib/sol2 -leng 
> -lmx -lm
>          arguments          =
> ->    CXX                   =
> ->    CXX flags:
>          CXXFLAGS           =
>          CXXDEBUGFLAGS      =
>          CXXOPTIMFLAGS      =
>          CXXLIBS            =
>          arguments          =
> ->    FC                    = f77
> ->    FC flags:
>          FFLAGS             = -I/opt/matlab13/extern/include -dalign
>          FDEBUGFLAGS        = -g
>          FOPTIMFLAGS        = -O
>          FLIBS              = -L/opt/matlab13/extern/lib/sol2 -leng 
> -lmx -lm
>          arguments          =
> ->    LD                    =
> ->    Link flags:
>          LDFLAGS            =
>          LDDEBUGFLAGS       = -g
>          LDOPTIMFLAGS       = -O
>          LDEXTENSION        =
>          arguments          =
> ->    LDCXX                 =
> ->    Link flags:
>          LDCXXFLAGS         =
>          LDCXXDEBUGFLAGS    =
>          LDCXXOPTIMFLAGS    =
>          LDCXXEXTENSION     =
>          arguments          =
> ----------------------------------------------------------------
> ->  -c  -I/opt/matlab13/extern/include 
> -I/opt/matlab13/simulink/include -DMATLAB_MEX_FILE    engdemo.C
>
> /home/fma/bin/mex: -c: not found

The problem is that the compiler command "gcc" is
missing in the compilation step.  This happens even
if I specify g++ for the compiler.  However, it compiles
OK if I bypass mex and call gcc directly.

Thanks for any suggestions...

Fred

-- 
Fred Ma, fma@doe.carleton.ca
Carleton University, Dept. of Electronics
1125 Colonel By Drive, Ottawa, Ontario
Canada, K1S 5B6
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads