Re: another shared object problem

From: Mary Haley (haley AT XXXXXX)
Date: Mon Jan 12 2004 - 22:09:35 MST

  • Next message: layesarr@ucad.sn: "isen script"

    >
    > Hello,
    >
    > I also seem to be having problems with creating and using
    > shared objects. This is my first try with this sort of
    > thing and I'm just trying to add a fairly simple C function.
    > Here's my ncl script:
    > external GAC "./gacsel.so"
    >
    > begin
    > rmin=.75
    > rmax=12.3
    > cint=0
    > GAC::gacsel(rmin, rmax, 5, cint, cmin, cmax)
    > print( "cint = " + cint )
    > end
    >
    > And here's the error message:
    > ncl gactest.ncl
    > Copyright (C) 1995-2003 - All Rights Reserved
    > University Corporation for Atmospheric Research
    > NCAR Command Language Version 4.2.0.a030
    > The use of this software is governed by a License Agreement.
    > See http://ngwww.ucar.edu/ncl/ for more details.
    > fatal:Error adding argument template for intrinsic function
    > fatal:syntax error: gacsel is not a procedure in package GAC
    >
    > I've followed all the steps in the page on Extending NCL
    > and had nothing more than some warnings from nhlcc about
    > a couple lines from standard ncarg includes not having
    > explicit types. Here are the steps, for clarity:
    > nhlcc -c Init.c
    > nhlcc -c gacsel.c
    > nhlcc -c gacsel_W.c
    > ld -o gacsel.so Init.o gacsel.o gacsel_W.o -G
    >
    > I'm pretty sure gacsel is defined in the shared lib so I'm
    > at a bit of a loss as to what's really wrong:
    > nm gacsel.so | grep gacsel
    > gacsel.so:
    > [43] | 1528| 736|FUNC |GLOB |0 |5 |gacsel
    > [24] | 0| 0|FILE |LOCL |0 |ABS |gacsel.c
    > [1] | 0| 0|FILE |LOCL |0 |ABS |gacsel.so
    > [46] | 2264| 212|FUNC |GLOB |0 |5 |gacsel_W
    > [29] | 0| 0|FILE |LOCL |0 |ABS |gacsel_W.c
    >
    > this is all happening on a Sun:
    > uname -a
    > SunOS frazil 5.8 Generic_108528-21 sun4u sparc SUNW,Ultra-5_10
    >
    > what am I missing???
    >
    > thanks,
    > dave

    Dave and others who are interested in this subject,

    As many of you know, if you have a Fortran subroutine, then
    you can run the WRAPIT script on it to create a shared object.
    This shared object can then be loaded from NCL using the "external"
    command, and the Fortran subroutine can be called directly
    from the NCL script.

    Doing the same thing for a C subroutine is more tedious, because we
    don't have a WRAPIT script for C code.

    To show a (relatively) simple example of how to create your
    own C wrapper, I have taken Dave's prototype for his "gascel"
    subroutine, created a dummy C subroutine by this name, and then
    created a wrapper for it.

    I have attached three files to this message:
     
        gacsel.c - the dummy "gacsel" subroutine, which doesn't
                     really do anything interesting.

        gacsel_W.c - the code for retrieving the arguments
                     from the NCL script and passing them
                     to the C subroutine. Also contains the code
                     for prototyping the function in NCL.

        gacsel.ncl - a dummy NCL script showing how to call the
                     "gacsel" subroutine.

    I will outline how to compile these files under Solaris (Sun) and
    under RedHat Linux. For examples of compilation on other systems, see
    the $NCARG_ROOT/bin/WRAPIT script, or visit:

      http://ngwww.ucar.edu/ngdoc/ng/ug/ncl/gsun/beyondbasics.html#Step_4

    Compiling and running under Solaris:

        nhlcc -c gacsel.c
        nhlcc -c gacsel_W.c
        ld -o gacsel.so gacsel.o gacsel_W.o -G
        ncl < gacsel.ncl

    Compiling and running under RedHat:

        nhlcc -c gacsel.c
        nhlcc -c gacsel_W.c
        ld -shared -o gacsel.so gacsel.o gacsel_W.o
        ncl < gacsel.ncl

    If all goes well, You should see output like this:

    (0) cint = 2.31
    (0) cmin = 0.75
    (0) cmax = 12.3

    If you have questions about this, please don't hesitate to
    send me a personal email.

    Cheers,

    --Mary

    -------------------------------------------------
    Mary Haley haley AT ucar.edu
    NCAR/SCD/VETS 303-497-1254 (voice)
    1850 Table Mesa Dr 303-497-1804 (fax)
    Boulder, CO 80305
    -------------------------------------------------








    _______________________________________________
    ncl-talk mailing list
    ncl-talk AT ucar.edu
    http://mailman.ucar.edu/mailman/listinfo/ncl-talk



    This archive was generated by hypermail 2b29 : Mon Jan 12 2004 - 22:12:24 MST