I wrote a minimal working example as below:
================================
// test_judy.cpp
#include "mex.h"
#include "matrix.h"
#include <Judy.h>

void test_judy(Pvoid_t p_judy_map)
{
        unsigned long index = 0L;
        int judy_rv;
        JError_t JErr;

        judy_rv = Judy1Test(p_judy_map, index, &JErr);

        return;
}


void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
        int idx=0;
        double* p_mapped_samples=NULL;
        Pvoid_t PJ1Array = (Pvoid_t) NULL; 

        test_judy(PJ1Array);

        /* create output variable  */
        plhs[0] = mxCreateDoubleMatrix(3, 1, mxREAL);
        if(plhs[0]==NULL){
                mexErrMsgTxt("could not create output matrix");
        }
        p_mapped_samples = mxGetPr(plhs[0]);
        for(idx=0; idx<3; idx++){
                p_mapped_samples[idx] = 1;
        }

        return;
}
================================

I tried to compile and link it with the following command:
================================
mex -g -v -lJudy test_judy.cpp
================================

But it gives me the following error:
================================
mex -g -v -lJudy test_judy.cpp
-> mexopts.sh sourced from directory (DIR = $HOME/.matlab/$REL_VERSION)
   FILE = /home/wfeng/.matlab/R2007b/mexopts.sh
----------------------------------------------------------------
->    MATLAB                = /usr/local/matlab2007b
->    CC                    = gcc
->    CC flags:
         CFLAGS             = -ansi -D_GNU_SOURCE -fexceptions -fPIC 
-fno-omit-frame-pointer -pthread
         CDEBUGFLAGS        = -g
         COPTIMFLAGS        = -O -DNDEBUG
         CLIBS              = 
-Wl,-rpath-link,/usr/local/matlab2007b/bin/glnxa64 
-L/usr/local/matlab2007b/bin/glnxa64 -lmx -lmex -lmat -lm -lm -lstdc++
         arguments          =  -DMX_COMPAT_32
->    CXX                   = g++
->    CXX flags:
         CXXFLAGS           = -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer 
-pthread
         CXXDEBUGFLAGS      = -g
         CXXOPTIMFLAGS      = -O -DNDEBUG
         CXXLIBS            = 
-Wl,-rpath-link,/usr/local/matlab2007b/bin/glnxa64 
-L/usr/local/matlab2007b/bin/glnxa64 -lmx -lmex -lmat -lm -lm
         arguments          =  -DMX_COMPAT_32
->    FC                    = g95
->    FC flags:
         FFLAGS             = -fexceptions -fPIC -fno-omit-frame-pointer
         FDEBUGFLAGS        = -g
         FOPTIMFLAGS        = -O
         FLIBS              = 
-Wl,-rpath-link,/usr/local/matlab2007b/bin/glnxa64 
-L/usr/local/matlab2007b/bin/glnxa64 -lmx -lmex -lmat -lm -lm
         arguments          =  -DMX_COMPAT_32
->    LD                    = g++
->    Link flags:
         LDFLAGS            = -pthread -shared 
-Wl,--version-script,/usr/local/matlab2007b/extern/lib/glnxa64/mexFunction.map 
-Wl,--no-undefined
         LDDEBUGFLAGS       = -g
         LDOPTIMFLAGS       = -O
         LDEXTENSION        = .mexa64
         arguments          =  -lJudy
->    LDCXX                 = 
->    Link flags:
         LDCXXFLAGS         = 
         LDCXXDEBUGFLAGS    = 
         LDCXXOPTIMFLAGS    = 
         LDCXXEXTENSION     = 
         arguments          =  -lJudy
----------------------------------------------------------------

-> g++ -c  -I/usr/local/matlab2007b/extern/include 
-I/usr/local/matlab2007b/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE 
-fPIC -fno-omit-frame-pointer -pthread  -DMX_COMPAT_32 -g test_judy.cpp

-> gcc -c  -I/usr/local/matlab2007b/extern/include 
-I/usr/local/matlab2007b/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE 
-fexceptions -fPIC -fno-omit-frame-pointer -pthread  -DMX_COMPAT_32 -g 
/usr/local/matlab2007b/extern/src/mexversion.c

-> g++ -g -pthread -shared 
-Wl,--version-script,/usr/local/matlab2007b/extern/lib/glnxa64/mexFunction.map 
-Wl,--no-undefined -o test_judy.mexa64  test_judy.o mexversion.o  -lJudy 
-Wl,-rpath-link,/usr/local/matlab2007b/bin/glnxa64 
-L/usr/local/matlab2007b/bin/glnxa64 -lmx -lmex -lmat -lm -lm

/usr/bin/ld: 
/usr/lib/gcc/x86_64-linux-gnu/4.0.3/../../../../lib64/libJudy.a(Judy1Test.o): 
relocation R_X86_64_32S against `a local symbol' can not be used when making a 
shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.0.3/../../../../lib64/libJudy.a: could not read 
symbols: Bad value
collect2: ld returned 1 exit status

    mex: link of 'test_judy.mexa64' failed.

??? Error using ==> mex at 208
Unable to complete successfully.
================================


As Alan pointed out, the -shared option could have something to do with it. So 
I went in and edited the file /home/wfeng/.matlab/R2007b/mexopts.sh by deleting 
the -shared option. The following is the result:
================================
mex -g -v -lJudy test_judy.cpp
-> mexopts.sh sourced from directory (DIR = $HOME/.matlab/$REL_VERSION)
   FILE = /home/wfeng/.matlab/R2007b/mexopts.sh
----------------------------------------------------------------
->    MATLAB                = /usr/local/matlab2007b
->    CC                    = gcc
->    CC flags:
         CFLAGS             = -ansi -D_GNU_SOURCE -fexceptions -fPIC 
-fno-omit-frame-pointer -pthread
         CDEBUGFLAGS        = -g
         COPTIMFLAGS        = -O -DNDEBUG
         CLIBS              = 
-Wl,-rpath-link,/usr/local/matlab2007b/bin/glnxa64 
-L/usr/local/matlab2007b/bin/glnxa64 -lmx -lmex -lmat -lm -lm -lstdc++
         arguments          =  -DMX_COMPAT_32
->    CXX                   = g++
->    CXX flags:
         CXXFLAGS           = -ansi -D_GNU_SOURCE -fPIC -fno-omit-frame-pointer 
-pthread
         CXXDEBUGFLAGS      = -g
         CXXOPTIMFLAGS      = -O -DNDEBUG
         CXXLIBS            = 
-Wl,-rpath-link,/usr/local/matlab2007b/bin/glnxa64 
-L/usr/local/matlab2007b/bin/glnxa64 -lmx -lmex -lmat -lm -lm
         arguments          =  -DMX_COMPAT_32
->    FC                    = g95
->    FC flags:
         FFLAGS             = -fexceptions -fPIC -fno-omit-frame-pointer
         FDEBUGFLAGS        = -g
         FOPTIMFLAGS        = -O
         FLIBS              = 
-Wl,-rpath-link,/usr/local/matlab2007b/bin/glnxa64 
-L/usr/local/matlab2007b/bin/glnxa64 -lmx -lmex -lmat -lm -lm
         arguments          =  -DMX_COMPAT_32
->    LD                    = g++
->    Link flags:
         LDFLAGS            = -pthread 
-Wl,--version-script,/usr/local/matlab2007b/extern/lib/glnxa64/mexFunction.map 
-Wl,--no-undefined
         LDDEBUGFLAGS       = -g
         LDOPTIMFLAGS       = -O
         LDEXTENSION        = .mexa64
         arguments          =  -lJudy
->    LDCXX                 = 
->    Link flags:
         LDCXXFLAGS         = 
         LDCXXDEBUGFLAGS    = 
         LDCXXOPTIMFLAGS    = 
         LDCXXEXTENSION     = 
         arguments          =  -lJudy
----------------------------------------------------------------

-> g++ -c  -I/usr/local/matlab2007b/extern/include 
-I/usr/local/matlab2007b/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE 
-fPIC -fno-omit-frame-pointer -pthread  -DMX_COMPAT_32 -g test_judy.cpp

-> gcc -c  -I/usr/local/matlab2007b/extern/include 
-I/usr/local/matlab2007b/simulink/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE 
-fexceptions -fPIC -fno-omit-frame-pointer -pthread  -DMX_COMPAT_32 -g 
/usr/local/matlab2007b/extern/src/mexversion.c

-> g++ -g -pthread 
-Wl,--version-script,/usr/local/matlab2007b/extern/lib/glnxa64/mexFunction.map 
-Wl,--no-undefined -o test_judy.mexa64  test_judy.o mexversion.o  -lJudy 
-Wl,-rpath-link,/usr/local/matlab2007b/bin/glnxa64 
-L/usr/local/matlab2007b/bin/glnxa64 -lmx -lmex -lmat -lm -lm

/usr/lib/gcc/x86_64-linux-gnu/4.0.3/../../../../lib64/crt1.o: In function 
`_start':../sysdeps/x86_64/elf/start.S:109: undefined reference to `main'
collect2: ld returned 1 exit status

    mex: link of 'test_judy.mexa64' failed.

??? Error using ==> mex at 208
Unable to complete successfully.
=========================================

I also tried to use gcc instead of g++ by renaming my file to .c. But it gave 
me the same errors.


Any ideas how I could fix this problem? 












Best Regards,
 
Wei


>>> Troy Heber <[email protected]> 9/18/2009 10:55 AM >>>
On 09/18/09 10:40, Wei Feng wrote:
> BTW, when I said I did not intentionally specify -shared option, I mean I did 
> not type in the g++ command. It was generated by the mex command that I used:
> ===================
> mex -g -v -largeArrayDims -I/usr/include -L/usr/lib -lJudy 
> mex_test_cir_map_target.cpp ...
> ===================

With out a copy of your code it is hard to guess. I have attached a
copy of the Judy1LCheck.c file from the Judy source. Can you compile
this as a simple test using:

gcc -o Judy1LCheck Judy1LCheck.c -lJudy -lm

You should then be able to run the resulting binary "Judy1LCheck". 

Please let us know the results from this simple test.

Thanks,

Troy

------------------------------------------------------------------------------
Come build with us! The BlackBerry&reg; Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9&#45;12, 2009. Register now&#33;
http://p.sf.net/sfu/devconf
_______________________________________________
Judy-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/judy-devel

Reply via email to