AIX

 View Only
Expand all | Collapse all

Calling Golang functions (shared library) from C programs on AIX 7.1 and 7.2

Jump to Best Answer
  • 1.  Calling Golang functions (shared library) from C programs on AIX 7.1 and 7.2

    Posted Fri October 01, 2021 08:28 AM
    Our product currently has a C program calling Golang functions in a shared library.  We have a business need to port the current code to run the C program on AIX7.1 and AIX7.2. This means we need to build Golang functions as a shared library on AIX, then build the C program to link to this shared library.  Doing this is simple on non-AIX OSes.  This link describes how: Calling Go Functions From Other Languages.  For AIX, Clement Chigot wrote the article Get Started With Go Language on AIX.  Unfortunately, I have not been successful. I encountered a number of issues along the way.  These issues are described in full detail in this github issue Building Golang shared library using gccgo on AIX 7.1 and calling the library from a C client.  I would appreciate very much if experts from the community can provide comments either directly to the github issue or in this thread.
    Thank you so much!

    ------------------------------
    Albert Chung
    ------------------------------


  • 2.  RE: Calling Golang functions (shared library) from C programs on AIX 7.1 and 7.2
    Best Answer

    Posted Fri October 01, 2021 10:24 AM

    Hi Albert,

    For now, "c-shared" buildmode isn't supported by both by Golang toolchain and gccgo. 
    In Golang toolchain, this is a known limitation as the internal ABI needs to be adapt for C code. 
    In gccgo toolchain, I'm not exactly sure about why it doesn't work, but libgo.a seems too depend on a Go main program. This looks like it's related to how shared libraries work on AIX. Everything must be resolved at link time. Thus libgo.a is looking for some symbols in "." (ie the main program) which won't be available in a C one.

    That's all I know for now. It'll require much more investigation in order to be able to fix it. 
    All I can do to help you for now is that the static way using c-archive should work as a workaround.  

    Thanks, 
    Clément



    ------------------------------
    Clement CHIGOT
    ------------------------------