C/C++

C/C++

C/C++

Your one-stop destination to learn and collaborate about the latest innovations in IBM C/C++ for z/OS compilers to develop high-performing C/C++ applications and system programs on z/OS while maximizing hardware use and improving application performance.

 View Only
Expand all | Collapse all

How to call a Metal-C function from plain C/C++ with LP64?

  • 1.  How to call a Metal-C function from plain C/C++ with LP64?

    Posted Wed June 18, 2014 07:49 PM

    Hi everyone,

    I'm a bit of a newbie when it comes to the mainframe in general, but I'm hoping someone can help me out. I'm playing around with calling a Metal-C function from another (non-Metal) C module. I saw this thread and I was able to compile and run the following as the author there did. However, now I'm trying to compile a 64-bit version instead (using the lp64 option), but I'm getting some binder errors.

    I compile with this sequence of USS commands:

    xlc -Wc,metal,longname,lp64 -S metal.cas -mgoff metal.sxlc -Wc,lp64 -c driver.cxlc -Wl,lp64 driver.o metal.o

    The last one results in this error:

    IEW2469E 9907 THE ATTRIBUTES OF A REFERENCE TO metal_function FROM SECTION          driver#C DO NOT MATCH THE ATTRIBUTES OF THE TARGET SYMBOL. REASON  2

    The reason code explanation for IEW2469E apparently is: The xplink attributes of the reference and target do not match.

    If I remove the lp64 option, my code compiles nicely and runs, so I'm not sure what to do to compile it as 64-bit. Does anyone have any ideas?

    metal.c

    #pragma prolog(metal_function,main)#pragma epilog(metal_function,main)int metal_function() {    return 42;}

    driver.c

    #include <stdio.h>int metal_function();int main() {    int result = metal_function();    printf("Result: %d\n", result);    return 0;}

     

    acrimon86


  • 2.  Re: How to call a Metal-C function from plain C/C++ with LP64?

    Posted Mon July 28, 2014 05:13 PM

    Hi,

    The reason why you got those messages is due to your main program (driver.c)  compiles with LP64 which turns on XPLINK,   but your Metal.c. is non-XPLINK (METAL does not support  XPLINK).

    The issues:

    • There is no LE environment in Metal C, so the stack and linkage in the Metal program is completely under the user's control. 
    • The linkage for your main program is XPLINK when compiles with LP64, so you must provide the appropriate  code to accept the XPLINK call.
    You can specify  #pragma linkage(metal_function,OS) or #pragma linkage(metal_function,OS_NOSTACK) in both driver.c and metal.c, it should solve your problem.
    ilam