• 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. How to link static library(.a) use xrun?

Stats

  • Locked Locked
  • Replies 3
  • Subscribers 65
  • Views 13713
  • 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

How to link static library(.a) use xrun?

greatedera
greatedera over 3 years ago

I have a static library file (libstatic.a) compiled from C language. Now I want to use some function in this library. But I don't know how to link this file using xrun. It seems that -sv_lib can only use shared library(dynamic lib, .so file), but not static library. Could someone tell me how to use this .a file using xrun? Thanks a lot!

  • Cancel
  • muffi
    muffi over 3 years ago

    Hi,

    This is documented in the following article:

    Article (20486869) Title: FAQ: Useful utilities to debug common build and link issues with custom shared object libraries
    URL: https://support.cadence.com/apex/ArticleAttachmentPortal?id=a1O0V000009MpKBUA0

    How to link a static library (.a file) with Xcelium

    An archive file with a .a extension is a static library and needs to be packed into an executable (or into another object such as a .so). The .a extension itself can only be used by the linker (ld) and not by other tools. Xcelium allows static libraries as part of the compile process. However, Xcelium does not itself link to DPI/VPI functions.

    This means functions in an archive (.a) will not be included unless they are specifically referenced by the compiled C code.

    Any direct DPI or VPI function must be dynamically linked.

    As a workaround, you can create a shared object file from an archive file and pass it on the xrun command line.

    You can convert static libraries into shared by invoking the linker directly.

    Example (32bit mode):

    UNIX> gcc -m32 -c -fpic -I$XLMHOME/tools/include ../src/cpp/tb.c <more sources>
    UNIX> ar r libdpi.a *.o
    UNIX> ld -m elf_i386 -shared -o libdpi.so -whole-archive libdpi.a

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • greatedera
    greatedera over 3 years ago in reply to muffi

    Hi muffi,

    I've tried according to this FAQ, but still has problem.

    Because I have static library already(suppose it's name is libmy123.a), so I just need to do below step:

    UNIX>  ld -m elf_x86_64 -shared -o libdpi.so -whole-archive libmy123.a

    But this command can failed with below msg:

    ld: libmy123.a(AES.o): relocation R_X86_64_32S against symbol `T_0' can not be used when making a shared object; recompile with -fPIC
    ld: libmy123.a(ECCP.o): relocation R_X86_64_32 against undefined symbol `ECC_P_plus_1_div2' can not be used when making a shared object; recompile with -fPIC
    ld: libmy123.a(utility.o): relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
    ld: final link failed: Nonrepresentable section on output

    It seems that my static library -- "libmy123.a" should be regenerated with "-fPIC". Am I right?

    Thanks!

    • Cancel
    • Vote Up 0 Vote Down
    • Cancel
  • greatedera
    greatedera over 3 years ago in reply to muffi

    And I have another question. In xrun user guide, I find below info:

    But when I call xrun with tb_top.sv and libmy124.a, below error happen:

    ncsim: *F,NOFDPI: Function XTS_SM4_crypto not found in default libdpi.

    Why this happen? It seems that xrun does not compile libmy123.a.

    I'm sure my lib and tb_top.sv has no problem, because, if I use VCS(Synopsys sim tool), my tb can work well. VCS can compile .a file directly.

    • 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