Home > Community > Forums > Functional Verification > C++ code through DPI simulation error?

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 C++ code through DPI simulation error? 

Last post Thu, Apr 26 2007 7:22 PM by archive. 18 replies.
Started by archive 26 Apr 2007 07:22 PM. Topic has 18 replies and 6107 views
Page 1 of 2 (19 items) 1 2 Next >
Sort Posts:
  • Thu, Apr 26 2007 7:22 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    C++ code through DPI simulation error? Reply

    Hi Cadence,

    I have write a simple C code through DPI example, it work OK.

    Then, I write a simple C++ code through DPI example. And found C++ compile and SV compile/elaboration pass. But  DPI link error? I guess its not DPI cannot found the lib as show in the ncsim log. Because the C code through DPI use the same configuration.
    My friend tried the same example in Synopsys VCS and work OK.


    //--- adder.cpp---
    #include
    #include "svdpi.h"
    extern "C"{
        int sum(int a, int b);
        }

    class CADD
    {
        private:
            int a;
            int b;
       
        public:
            CADD();
            ~CADD();
            int add(int a, int b);

    };

    CADD::CADD()
    {
    }

    CADD::~CADD()
    {
    }

    int CADD::add(int a, int b)
    {
        int c = a +b;
        return c;
           
    }

    int sum(int a, int b)
    {
        CADD add1;
        int result = add1.add(a,b);
        printf("the result is %d\n",result);
    }
    //------------

    //-- C++ compile makefile
    #!/bin/sh
    g++ adder.cpp -fPIC -shared -o libdpi.so -I $CDS_INST_DIR/tools/inca/include
    //-------------

    //-- switch add to ncsim
    -sv_lib ./src/test_sv/libdpi.so
    //------------

    Run simulation and output:
    ncsim: 05.83-s003: (c) Copyright 1995-2007 Cadence Design Systems, Inc.
    snapshot worklib.top:module (SSS) is up to date (no update required).
    Loading snapshot worklib.top:module .................... Done
    ncsim: *W,NOLDPI: Unable to load ./src/test_sv/libdpi.so.
    OSDLERROR: /cad/cadence/IUS583-s003-linux/tools.lnx86/lib/libgcc_s.so.1: version cannot open shared object file: No such file or directory or file is not valid ELFCLASS32 library..
    ncsim: *F,NOFDPI: Function sum not found in any of the shared object specified with -SV_LIB switch.
    ncsim: Memory Usage - 17.9M program + 10.4M data = 28.3M total
    ncsim: CPU Usage - 0.0s system + 0.1s user = 0.2s total (1.0s, 15.8% cpu)

    Best regards,
    Davy


    Originally posted in cdnusers.org by davyzhu
    • Post Points: 0
  • Thu, Apr 26 2007 7:27 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: C++ code through DPI simulation error? Reply

    Continue the last post:

    The sv file
    //---test_dpi_class.sv
    module top;
    int c = 1;
    int d = 2;
    int out;
    import "DPI-C" function int sum(input int a, input int b);
    initial begin
    out = sum(c, d);
    $strobe("out is %d\n",out);
    end
    endmodule
    //---------

    And please add
    #include
    to the c++ file

    Best regards,
    Davy


    Originally posted in cdnusers.org by davyzhu
    • Post Points: 0
  • Mon, Apr 30 2007 7:14 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: C++ code through DPI simulation error? Reply

    Posted By davyzhu on 4/26/2007 7:22 PM

    //-- C++ compile makefile
    #!/bin/sh
    g++ adder.cpp -fPIC -shared -o libdpi.so -I $CDS_INST_DIR/tools/inca/include
    //-------------

    //-- switch add to ncsim
    -sv_lib ./src/test_sv/libdpi.so
    //------------

    Run simulation and output:
    ncsim: 05.83-s003: (c) Copyright 1995-2007 Cadence Design Systems, Inc.
    snapshot worklib.top:module (SSS) is up to date (no update required).
    Loading snapshot worklib.top:module .................... Done
    ncsim: *W,NOLDPI: Unable to load ./src/test_sv/libdpi.so.
    OSDLERROR: /cad/cadence/IUS583-s003-linux/tools.lnx86/lib/libgcc_s.so.1: version cannot open shared object file: No such file or directory or file is not valid ELFCLASS32 library..
    ncsim: *F,NOFDPI: Function sum not found in any of the shared object specified with -SV_LIB switch.
    ncsim: Memory Usage - 17.9M program + 10.4M data = 28.3M total
    ncsim: CPU Usage - 0.0s system + 0.1s user = 0.2s total (1.0s, 15.8% cpu)

    Best regards,
    Davy


    >> g++ adder.cpp -fPIC -shared -o libdpi.so -I $CDS_INST_DIR/tools/inca/include
    //-------------

    Did you check to see that this step was successful? Do a find . -name "libdpi.so" to see if this file got created.

    >> -sv_lib ./src/test_sv/libdpi.so
    //------------

    This seems to suggest that you are running the simulation in a dir different than the SO file got created. To make things simple, I would try running this in same dir or create a "link" to the SO file in current dir.

    >> ncsim: *W,NOLDPI: Unable to load ./src/test_sv/libdpi.so.
    >> OSDLERROR: /cad/cadence/IUS583-s003-linux/tools.lnx86/lib/libgcc_s.so.1:
    >> version cannot open shared object file: No such file or directory or

      The "find" command should be tried first to see if this file exists.

    >> file is not valid ELFCLASS32 library..

    Or this may also be an issue - are you running things on  same machine? Say linux or Solaris?

    Regards
    Ajeetha, CVC
    www.noveldv.com






    Originally posted in cdnusers.org by ajeetha
    • Post Points: 0
  • Mon, Apr 30 2007 7:21 AM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: C++ code through DPI simulation error? Reply


    Try setting you LD_LIBRARY_PATH env var as well. Either to "." or to the full path to where the libdpi.so resides.
    Insure that your libdpi.so is compiled for the same platform your simulation is running on (i.e. Linux or Solaris). If
    you would like a few small example - please drop me a line.

    Jim McGrath


    Originally posted in cdnusers.org by Jim McGrath
    • Post Points: 0
  • Mon, May 7 2007 7:41 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: C++ code through DPI simulation error? Reply

    Hi Ajeetha and Jim,

    I was on vacation last week and sorry for reply late.
    I have tried your methods, and found
    1. ./libdpi.so exist (I moved it to work dir)
    2. /cad/cadence/IUS583-s003-linux/tools.lnx86/lib/libgcc_s.so.1 exist
    3. Make sure libdpi.so is compiled for the same platform my simulation is running on.
    4. add work path to LD_LIBRARY_PATH

    But the simulation also failed and output the same error as previous post.

    Hi Jim,

    Could you please give out small example on C++ by DPI? Thanks in advance!

    Best regards,
    Davy


    Originally posted in cdnusers.org by davyzhu
    • Post Points: 0
  • Mon, May 7 2007 7:59 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: C++ code through DPI simulation error? Reply

    Hi Jim,

    I have successfully pass a C by DPI example before. And the simulation environment is similar to the C++ by DPI example.
    Could you please give out your example or help to run my small example to make sure the tool is all right? Thanks a lot!

    Best regards,
    Davy


    Originally posted in cdnusers.org by davyzhu
    • Post Points: 0
  • Mon, May 14 2007 6:26 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: C++ code through DPI simulation error? Reply

    Hi all,

    Anyone could help to demonstrate whether C++ by DPI do work or not?
    Any suggestions will be appreciated!

    Best regards,
    Davy


    Originally posted in cdnusers.org by davyzhu
    • Post Points: 0
  • Mon, May 14 2007 10:37 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: C++ code through DPI simulation error? Reply

    Davy,

    With ncsim-5.83, i am able to use the large C++ reference design in my SV testbench.

    Infact, i am not only using the C++, but also has got the Matlab functions as well.

    The above adder example seems to be Ok. Do append extern "C" before the function which you are going to call through SV. That's it.

    Since, the work done being proprietary i am unable to write in detail. But DPI with C++ do work.

    -Vivek


    Originally posted in cdnusers.org by prasad_vc
    • Post Points: 0
  • Mon, May 14 2007 10:46 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: C++ code through DPI simulation error? Reply

    Hi Vivek,

    Thank you so much for the help and I will check my environment thoroughly.

    And I am very interested in Matlab function called by DPI, is there any reference given out by Cadence?

    Best regards,
    Davy


    Originally posted in cdnusers.org by davyzhu
    • Post Points: 0
  • Mon, May 14 2007 10:52 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: C++ code through DPI simulation error? Reply

    Sorry to say, but no documentation is available for accessing the foreign language function through DPI, apart from C. The cadence support for the same was very bad, all they kept telling me is to use the new software from the matlab to be able to use the matlab function in SV tetbench through DPI.

    If you have any specific error, post here or mail me at prasad_vc@yahoo.com and i'll suggest the way to overcome the same.

    -Vivek


    Originally posted in cdnusers.org by prasad_vc
    • Post Points: 0
  • Mon, May 14 2007 11:19 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: C++ code through DPI simulation error? Reply

    Hi Vivek,

    Thanks a lot :)

    I have re-run the adder.cpp by DPI on IUS61. It seems ncsim can not find the libstdc++.so? Is this file provide by Cadence or a shared lib come with g++?

    IUS on SunOS:
    ncsim: *W,NOLDPI: Unable to load ./libdpi.so.
    OSDLERROR: ld.so.1: ncsim: fatal: libstdc++.so.2.10.0: open failed: No such file or directory.
    ncsim: *F,NOFDPI: Function sum not found in any of the shared object specified with -SV_LIB switch.

    IUS on Linux:
    ncsim: *W,NOLDPI: Unable to load ./libdpi.so.
    OSDLERROR: /cad/cadence/IUS61/lnx86/tools.lnx86/lib/libgcc_s.so.1: version `GCC_3.3' not found (required by /usr/lib/libstdc++.so.5).
    ncsim: *F,NOFDPI: Function sum not found in any of the shared object specified with -SV_LIB switch.

    Best regards,
    Davy


    Originally posted in cdnusers.org by davyzhu
    • Post Points: 0
  • Mon, May 14 2007 11:33 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: C++ code through DPI simulation error? Reply

    Davy,

    Try the following in any of your environment.

    setenv LD_LIBRARY_PATH /cad/cadence/IUS61/lnx86/tools.lnx86/systemc/gcc/3.2.3/install/lib

    Put the above statement in your .cshrc file and save and exit. Source the .cshrc file from the terminal from where you are going to invoke the simulation and finally run the simulation.

    If this doesn't work, send me the output of the following command: gcc -v

    -Vivek






    Originally posted in cdnusers.org by prasad_vc
    • Post Points: 0
  • Mon, May 14 2007 11:36 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: C++ code through DPI simulation error? Reply

    Hi Vivek,

    Continue the last post,

    I have check the shared lib file.
    IUS on SunOS:
    libstdc++.so.2.10.0 CANNOT found on SunOS /usr/lib

    IUS on Linux:
    Both /cad/cadence/IUS61/lnx86/tools.lnx86/lib/libgcc_s.so.1 and /usr/lib/libstdc++.so.5 CAN be found
    But what's "version `GCC_3.3' not found " mean?
    Shall the lib/libgcc_s.so.1 be compiled with GCC_3.3?

    Any Cadence engineer can show me the right direction?

    Best regards,
    Davy


    Originally posted in cdnusers.org by davyzhu
    • Post Points: 0
  • Mon, May 14 2007 11:51 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: C++ code through DPI simulation error? Reply

    Hi Vivek,

    I add
    setenv LD_LIBRARY_PATH /cad/cadence/IUS61/lnx86/tools.lnx86/systemc/gcc/3.2.3/install/lib:{$LD_LIBRARY_PATH}

    When I compile the c++ file on Linux machine, g++ give out errors:
    g++: Internal error: Segmentation fault (program as)
    Please submit a full bug report.
    See for instructions.

    >> gcc -v
    Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/specs
    Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
    Thread model: posix
    gcc version 3.2.3 20030502 (Red Hat Linux 3.2.3-52)

    Best regards,
    Davy


    Originally posted in cdnusers.org by davyzhu
    • Post Points: 0
  • Mon, May 14 2007 11:56 PM

    • archive
    • Top 75 Contributor
    • Joined on Fri, Jul 4 2008
    • Posts 88
    • Points 4,930
    RE: C++ code through DPI simulation error? Reply

    Davy,

    Would it be possible to zip and send the programs so that i can try those out? Kindly send it to prasad_vc@yahoo.com

    GCC_3.3 means to me, the tool has used the gcc version 3.3 to build and now we are using the gcc 3.2.3 version. I guess you are right that the libgcc_s.so.1 should be compiled with GCC_3.3.

    -Vivek.


    Originally posted in cdnusers.org by prasad_vc
    • Post Points: 0
Page 1 of 2 (19 items) 1 2 Next >
Sort Posts:
Started by archive at 26 Apr 2007 07:22 PM. Topic has 18 replies.