🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.soft-sys.matlab
Article #208

Re: C++ & matlab engine, gcc versus SUNWspro cc

#208
From: 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
Technical Details
Message-ID: <3E229714.4080404@doe.carleton.ca>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.uchicago.edu!newsswitch.lcs.mit.edu!snoopy.risq.qc.ca!torn!cunews!not-for-mail
References: <3E2273CD.50300@doe.carleton.ca>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,5b60b5f5adec6f3a
X-Google-Attributes: gid11318c,public
X-Google-Thread: 106e3f,5b60b5f5adec6f3a
X-Google-Attributes: gid106e3f,public
X-Google-Thread: 11035d,5b60b5f5adec6f3a
X-Google-Attributes: gid11035d,public
X-Google-ArrivalTime: 2003-01-13 02:40:02 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.uchicago.edu!newsswitch.lcs.mit.edu!snoopy.risq.qc.ca!torn!cunews!not-for-mail
From: Shing-Fat Fred Ma <fma@doe.carleton.ca>
Newsgroups: comp.soft-sys.matlab,comp.unix.solaris,gnu.gcc.help
Subject: Re: C++ & matlab engine, gcc versus SUNWspro cc
Date: 13 Jan 2003 10:38:15 GMT
Organization: Carleton University, Ottawa, Canada
Lines: 153
Message-ID: <3E229714.4080404@doe.carleton.ca>
References: <3E2273CD.50300@doe.carleton.ca>
NNTP-Posting-Host: malawi.doe.carleton.ca
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
User-Agent: Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.0.1) Gecko/20020920 Netscape/7.0
X-Accept-Language: en-us, en