Thread Subject: Mex error in 64-bit 2008a Mac OS X beta

Subject: Mex error in 64-bit 2008a Mac OS X beta

From: Sridhar Mahadevan

Date: 23 Jul, 2008 12:47:01

Message: 1 of 3


I'm having trouble mex'ing some C++ code, which I have been able
to compile successfully both on 64-bit Windows, Linux, as well as 32-bit Mac
MATLAB versions. The problem is in the link loader (_mexFunction is
undefined).

The output of mex -v -g is given below. Any help would be much
appreciated!

Thanks.

- Sridhar

mex -g -v -largeArrayDims FastGSOGP.cpp
-> mexopts.sh sourced from directory (DIR = $MATLAB/bin)
   FILE = /Applications/MATLAB_R2008a/bin/mexopts.sh
-----------------------------------------------------------
-----
-> MATLAB = /Applications/MATLAB_R2008a
-> CC = gcc-4.0
-> CC flags:
         CFLAGS = -fno-common -no-cpp-precomp -arch x86_64 -
isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -
fexceptions
         CDEBUGFLAGS = -g
         COPTIMFLAGS = -O2 -DNDEBUG
         CLIBS = -L/Applications/MATLAB_R2008a/bin/maci64 -lmx -
lmex -lmat -lstdc++
         arguments =
-> CXX = g++-4.0
-> CXX flags:
         CXXFLAGS = -fno-common -no-cpp-precomp -fexceptions -
arch x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-
version-min=10.5
         CXXDEBUGFLAGS = -g
         CXXOPTIMFLAGS = -O2 -DNDEBUG
         CXXLIBS = -L/Applications/MATLAB_R2008a/bin/maci64 -lmx -
lmex -lmat -lstdc++
         arguments =
-> FC = gfortran
-> FC flags:
         FFLAGS = -m64
         FDEBUGFLAGS = -g
         FOPTIMFLAGS = -O
         FLIBS = -L/Applications/MATLAB_R2008a/bin/maci64 -lmx -
lmex -lmat -L -lgfortran -L -lgfortranbegin
         arguments =
-> LD = gcc-4.0
-> Link flags:
         LDFLAGS = -Wl,-twolevel_namespace -undefined error -arch
x86_64 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk -mmacosx-
version-min=10.5 -bundle -Wl,-
exported_symbols_list,/Applications/MATLAB_R2008a/extern/lib/maci64/me
xFunction.map
         LDDEBUGFLAGS = -g
         LDOPTIMFLAGS = -O
         LDEXTENSION = .mexmaci64
         arguments =
-> LDCXX =
-> Link flags:
         LDCXXFLAGS =
         LDCXXDEBUGFLAGS =
         LDCXXOPTIMFLAGS =
         LDCXXEXTENSION =
         arguments =
-----------------------------------------------------------
-----

-> g++-4.0 -c -I/Applications/MATLAB_R2008a/extern/include -
DMATLAB_MEX_FILE -fno-common -no-cpp-precomp -fexceptions -arch
x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-
min=10.5 -g "FastGSOGP.cpp"

-> gcc-4.0 -c -I/Applications/MATLAB_R2008a/extern/include -
DMATLAB_MEX_FILE -fno-common -no-cpp-precomp -arch x86_64 -
isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -
fexceptions -g "/Applications/MATLAB_R2008a/extern/src/mexversion.c"

-> gcc-4.0 -g -Wl,-twolevel_namespace -undefined error -arch x86_64 -
Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-
min=10.5 -bundle -Wl,-
exported_symbols_list,/Applications/MATLAB_R2008a/extern/lib/maci64/me
xFunction.map -o "FastGSOGP.mexmaci64" FastGSOGP.o mexversion.o -
L/Applications/MATLAB_R2008a/bin/maci64 -lmx -lmex -lmat -lstdc++

Undefined symbols:
  "_mexFunction", referenced from:
     -exported_symbols_list command line option
ld: symbol(s) not found
collect2: ld returned 1 exit status

    mex: link of ' "FastGSOGP.mexmaci64"' failed.


Subject: Mex error in 64-bit 2008a Mac OS X beta

From: Brian Arnold

Date: 24 Jul, 2008 13:17:08

Message: 2 of 3

Hi Sridhar,

Try the following to diagnose the root cause.

Run the first g++ command, with ! before the command to escape out to
the shell and run it, then run !nm FastGSOGP.o.

The output of nm should contain a line with "T _mexFunction". If it
does not show up, or if it shows up with lots of characters before and
after the name (for example, __Z11mexFunctionsPP11mxArray_tagsPPKS_),
then something may be wrong with how it is being declared in the source
file FastGSOGP.cpp.

The declaration in your source file should match the parameter types
exactly, like this:

void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )

The integer arguments must be the intrinsic "int" type (without
qualifiers), for this signature to work on all platforms. Use of short
or long integer, or other derived types, will cause the signature to
fail to be an exact match for certain compilers.

Brian



Sridhar Mahadevan wrote:
> I'm having trouble mex'ing some C++ code, which I have been able
> to compile successfully both on 64-bit Windows, Linux, as well as 32-bit Mac
> MATLAB versions. The problem is in the link loader (_mexFunction is
> undefined).
>
> The output of mex -v -g is given below. Any help would be much
> appreciated!
>
> Thanks.
>
> - Sridhar
>
> mex -g -v -largeArrayDims FastGSOGP.cpp
> -> mexopts.sh sourced from directory (DIR = $MATLAB/bin)
> FILE = /Applications/MATLAB_R2008a/bin/mexopts.sh
> -----------------------------------------------------------
> -----
> -> MATLAB = /Applications/MATLAB_R2008a
> -> CC = gcc-4.0
> -> CC flags:
> CFLAGS = -fno-common -no-cpp-precomp -arch x86_64 -
> isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -
> fexceptions
> CDEBUGFLAGS = -g
> COPTIMFLAGS = -O2 -DNDEBUG
> CLIBS = -L/Applications/MATLAB_R2008a/bin/maci64 -lmx -
> lmex -lmat -lstdc++
> arguments =
> -> CXX = g++-4.0
> -> CXX flags:
> CXXFLAGS = -fno-common -no-cpp-precomp -fexceptions -
> arch x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-
> version-min=10.5
> CXXDEBUGFLAGS = -g
> CXXOPTIMFLAGS = -O2 -DNDEBUG
> CXXLIBS = -L/Applications/MATLAB_R2008a/bin/maci64 -lmx -
> lmex -lmat -lstdc++
> arguments =
> -> FC = gfortran
> -> FC flags:
> FFLAGS = -m64
> FDEBUGFLAGS = -g
> FOPTIMFLAGS = -O
> FLIBS = -L/Applications/MATLAB_R2008a/bin/maci64 -lmx -
> lmex -lmat -L -lgfortran -L -lgfortranbegin
> arguments =
> -> LD = gcc-4.0
> -> Link flags:
> LDFLAGS = -Wl,-twolevel_namespace -undefined error -arch
> x86_64 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk -mmacosx-
> version-min=10.5 -bundle -Wl,-
> exported_symbols_list,/Applications/MATLAB_R2008a/extern/lib/maci64/me
> xFunction.map
> LDDEBUGFLAGS = -g
> LDOPTIMFLAGS = -O
> LDEXTENSION = .mexmaci64
> arguments =
> -> LDCXX =
> -> Link flags:
> LDCXXFLAGS =
> LDCXXDEBUGFLAGS =
> LDCXXOPTIMFLAGS =
> LDCXXEXTENSION =
> arguments =
> -----------------------------------------------------------
> -----
>
> -> g++-4.0 -c -I/Applications/MATLAB_R2008a/extern/include -
> DMATLAB_MEX_FILE -fno-common -no-cpp-precomp -fexceptions -arch
> x86_64 -isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-
> min=10.5 -g "FastGSOGP.cpp"
>
> -> gcc-4.0 -c -I/Applications/MATLAB_R2008a/extern/include -
> DMATLAB_MEX_FILE -fno-common -no-cpp-precomp -arch x86_64 -
> isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5 -
> fexceptions -g "/Applications/MATLAB_R2008a/extern/src/mexversion.c"
>
> -> gcc-4.0 -g -Wl,-twolevel_namespace -undefined error -arch x86_64 -
> Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-
> min=10.5 -bundle -Wl,-
> exported_symbols_list,/Applications/MATLAB_R2008a/extern/lib/maci64/me
> xFunction.map -o "FastGSOGP.mexmaci64" FastGSOGP.o mexversion.o -
> L/Applications/MATLAB_R2008a/bin/maci64 -lmx -lmex -lmat -lstdc++
>
> Undefined symbols:
> "_mexFunction", referenced from:
> -exported_symbols_list command line option
> ld: symbol(s) not found
> collect2: ld returned 1 exit status
>
> mex: link of ' "FastGSOGP.mexmaci64"' failed.
>
>

Subject: Mex error in 64-bit 2008a Mac OS X beta

From: Sridhar Mahadevan

Date: 25 Jul, 2008 00:38:02

Message: 3 of 3

Brian Arnold <Brian.Arnold@mathworks.com> wrote in message
<488880D4.9090606@mathworks.com>...
> Hi Sridhar,
>
> Try the following to diagnose the root cause.
>
> Run the first g++ command, with ! before the command to escape out to
> the shell and run it, then run !nm FastGSOGP.o.
>
> The output of nm should contain a line with "T _mexFunction". If it
> does not show up, or if it shows up with lots of characters before and
> after the name (for example, __Z11mexFunctionsPP11mxArray_tagsPPKS_),
> then something may be wrong with how it is being declared in the source
> file FastGSOGP.cpp.
>
> The declaration in your source file should match the parameter types
> exactly, like this:
>
> void mexFunction( int nlhs, mxArray *plhs[],
> int nrhs, const mxArray *prhs[] )
>
> The integer arguments must be the intrinsic "int" type (without
> qualifiers), for this signature to work on all platforms. Use of short
> or long integer, or other derived types, will cause the signature to
> fail to be an exact match for certain compilers.
>
> Brian


Brian,

Many thanks! You hit the nail on the head. I had to reformat the declaration
of mexFunction. This now works perfectly.



Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
mex 64bit mac o... Sridhar Mahadevan 23 Jul, 2008 08:50:39
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com