ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Export from SRVPGM

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Export from SRVPGM

    Hey! I am creating a service program in C++. It contains the implementation of the classes. To avoid error MCH4431 in the future, I create a service program using an export list.

    At the same time, I feel some inconvenience. Due to the mangling of names, something like EXPORT SYMBOL ("Length__Q3_3oli2v118Db2StringBaseConstXTQ3_3o li2 v19Db2String_CFv") has to be added to the export list. Isn't there any other way to export names from C ++ modules?

    In addition, I have a fear that with some next update of the compiler, it will begin to mangle the names differently. In this case, after adding functionality to the service program and assembling it, it will export names other than those already used by existing programs. This will require recompiling all programs that depend on this service, which can be extremely difficult.

    However, the latter concern is a little dispelled by the fact that there are many system service programs that also export mangled names. If the compiler starts to mangle names differently, then all programs it creates that use the mentioned system service programs will not work.

    Does anyone have information on this topic?

  • #2
    I am not expert in C++, but I think you can prevent the external name from being mangled by using extern "C"

    Comment


    • #3
      Originally posted by Barbara Morris View Post
      I am not expert in C++, but I think you can prevent the external name from being mangled by using extern "C"

      http://www.ibm.com/docs/en/i/7.4?top...angling-c-only
      Barbara, thanks for the advice. However, your advice only applies to separately implemented functions. And that is limited: it will not be possible to overload such functions.
      For me, SRVPGM is designed to store the implementation of C ++ classes, and in C ++, mangling plays an extremely important role. Without mangling, C ++ becomes C.
      All in all I found a mangle management tool. This is the namemangling pragma, which specifies the name mangling version. By specifying a specific version of name mangling in source code, I can be sure that any version of the IBM i compiler will mange names in that source code in the same way. This, by the way, is done in the C ++ standard library.

      Comment


      • #4
        Originally posted by d7d1cd_ View Post
        Barbara, thanks for the advice. However, your advice only applies to separately implemented functions. And that is limited: it will not be possible to overload such functions. For me, SRVPGM is designed to store the implementation of C ++ classes, and in C ++, mangling plays an extremely important role. Without mangling, C ++ becomes C.
        I sould suggest having a module intended to provide non-mangled versions of the names. We use an architecture like this:
        • [
        • MODULEB = Base module, uses C-style non-mangled names. Names are selected to avoid the need for overloading. C++ routines use exterm "C".
        • MODULEC = C++ module. Wraps the base module with C++ wrappers that implement a nice class, uses overloading, et al, to make things as elegant as possible for C++ callers.
        • MODULER = RPG module. Wraps the base module with RPG wrappers to make it elegant to call from RPG.


        These are bound together to make one service program, and prototypes are included for each caller's language. Surprisingly, its not that much extra work, since most of the real logic is done in the base module, and the others are just wrappers to simplify things for the callers.

        Comment


        • #5
          Scott, I got your idea. But my situation is different. My service program is written solely for use by its C ++ programs (with class hierarchy, function overloads, virtual methods, and other C ++ features). Of course, this service will have separate functions that can be used in C or RPG programs. But for this, I planned to make a separate wrapper service program that will use the main service program, but export only the necessary names and only in an undistorted form.

          Comment

          Working...
          X