• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Functional Verification
  3. C++ code through DPI simulation error?

Stats

  • Locked Locked
  • Replies 18
  • Subscribers 64
  • Views 27581
  • Members are here 0
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

C++ code through DPI simulation error?

archive
archive over 18 years ago

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
  • Cancel
  • archive
    archive over 18 years ago

    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
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 18 years ago

    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
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 18 years ago


    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
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 18 years ago

    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
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 18 years ago

    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
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 18 years ago

    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
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 18 years ago

    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
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 18 years ago

    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
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 18 years ago

    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
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • archive
    archive over 18 years ago

    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
    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
>

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

© 2025 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information