Linker flag -U in cob32 or cob64

I try to understand how Visual COBOL works in Eclipse GUI.  I turn verbose mode


I saw this information in the build output windows:

[cobollink] Linking Hello...
[cobollink] cob32 -g -x -t -oHello Hello.o -U
[cobollink] Link complete with no errors
[cobollink]

I can understand purposes about these flags: -g,  -t, -x from

But I really do not understand flag -U
The document says :

Dynamically Load Unresolved Reference (-U)

Causes any unresolved reference to be treated as a COBOL program to be dynamically loaded. Normally, such references would cause a fatal error at link time when creating a system executable, or cause a fatal error at run-time for callable shared objects.
But I did not see any difference to use -U or without -U in the final executable file.
Is there anyway to  turn off -U flag in Visual COBOL?
Really appreciated.

Tags:

  • The 'Dynamically Load Unresolved Reference (-U)' means the entries ( programs ) which were not found at the link step

    will de dynamically called when the program will be executed.

    For reference:

    (

    documentation.microfocus.com/.../index.jsp;resultof="cob" "flags"

    Micro Focus Developer > Micro Focus Visual COBOL 2.3 Update 1 for Eclipse (UNIX) > General Reference > Command line reference > Compiling and Linking from the Command Line

    cob Flags

    )

    1. As an example take this HELLO.cbl code:

    123456 procedure division.

              display ":) Hello World"

              call  "BONJOUR"

    2. When compiling/linking with 'cob -x HELLO.cbl', you'll get:

    HELLO.o: In function `HELLO':

    HELLO.cbl:(.text 0x4b): undefined reference to `BONJOUR'

    collect2: ld a retourn▒ 1 code d'▒tat d'ex▒cution  ( <- OS ld error )

    This happens because the ld linker can't resolve the entry point 'BONJOUR'...

    3. When compiling/linking with 'cob -z HELLO.cbl', The compilation will be fine.

    But when executing you'll get

    cobrun HELLO.so

    Load error : file 'HELLO.so'

    error code: 198, pc=0, call=1, seg=0

    198     Load failure (BONJOUR)

    RTS 198 = COBRT198 Load failure (Fatal) ...

    (documentation.microfocus.com/.../index.jsp;resultof="cobrt" "198" )

    4. When compiling/linking with 'cob -xU HELLO.cbl', you'll get:

    Cobol program "BONJOUR" undefined. Assuming it will be dynamically loaded.

    The launch of the linked program will give:

    HELLO

    :) Hello World

    Load error : file 'BONJOUR'

    error code: 173, pc=0, call=1, seg=0

    173     Called program file not found in drive/directory

    Now have such a BONJOUR.cbl program:

    BONJOUR.cbl

    123456 procedure division.

              display ":) Bonjour le monde"

    that you would compile link this way ( cob -z BONJOUR.cbl ) which creates BONJOUR.so

    Now, when launching the HELLO program, you'll get:

    HELLO

    :) Hello World

    :) Bonjour le monde

    See here that the BONJOUR.so library was dynamically called ...

    5. As an alternative way to link. Now let's link BONJOUR.cbl this way 'cob -Z BONJOUR.cbl' which will produce libBONJOUR.so

    and link HELLO.cbl this way 'cob -x -L. -lBONJOUR HELLO.cbl'

    and run HELLO. You'll get

    HELLO

    :) Hello World

    :) Bonjour le monde

    Regards

    Yvon

  • Thank you, Yvon

    You gave me a very good example and use case for linker -U flag.

    Have you ever encounter the following issue:

    My source code is as simple as yours: (COB64.cbl)

         ....

          procedure division.

              DISPLAY "HELLO WORLD".

              DISPLAY "Press <CR> to terminate."

              STOP ' '.

              goback.

          ...

    $cob64 -g -x -t -oCOB64 COB64.o

    ./COB64

    HELLO WORLD

    Press <CR> to terminate.

    But if  I do this

    $ cob64 -g -x -t -oCOB64 COB64.o -U

    Cobol program "socket" undefined. Assuming it will be dynamically loaded.

    Cobol program "pthread_mutex_destroy" undefined. Assuming it will be dynamically loaded.

    Cobol program "__strdup" undefined. Assuming it will be dynamically loaded.

    Cobol program "sigemptyset" undefined. Assuming it will be dynamically loaded.

    Cobol program "read" undefined. Assuming it will be dynamically loaded.

    Cobol program "getcwd" undefined. Assuming it will be dynamically loaded.

    Cobol program "strxfrm" undefined. Assuming it will be dynamically loaded.

    Cobol program "tan" undefined. Assuming it will be dynamically loaded.

    Cobol program "fread" undefined. Assuming it will be dynamically loaded.

    Cobol program "getpwuid" undefined. Assuming it will be dynamically loaded.

    Cobol program "rmdir" undefined. Assuming it will be dynamically loaded.

    Cobol program "pthread_mutexattr_init" undefined. Assuming it will be dynamically loaded.

    Cobol program "__strtod_internal" undefined. Assuming it will be dynamically loaded.

    Cobol program "vfprintf" undefined. Assuming it will be dynamically loaded.

    Cobol program "iconv_open" undefined. Assuming it will be dynamically loaded.

    Cobol program "setenv" undefined. Assuming it will be dynamically loaded.

    ....

    ....

    $ ./COB64

    Segmentation fault (core dumped)

    linker flag -U makes  all standard C functions  as external loadable COBOL function.  when I run it. the application crashed.

    Without -U,  everything runs fine.

    Did I miss any COBOL library,  CopyBooks?  

    Really appreciated.

  • You should use the .cbl extension in the link. Not . o.

    When .cbl: cob64 -g -x -t -oCOB64 COB64.cbl --> You compile and link

    When .o:    cob64 -g -x -t -oCOB64 COB64.o   --> You only link

    ? Would you rename COB64.cbl to another name?

    :) Yvonl

  • I rename COB64.cbl as HELLO.cbl

    cob64 -g -x -t -oHELLO HELLO.cbl  

    ./HELLO    --- works

    cob64 -g -x -t -oHELLO HELLO.o

    ./HELLO  -- works

    cob64 -g -x -t -oHELLO HELLO.o -U

    linker flag -U makes  all standard C functions  as external loadable COBOL function.

    ./HELLO  -- crash    

    Maybe you never encounter above issue as me.

    On your machine:

    cob64 -g -x -t -oHELLO HELLO.o -U  

    is just as good as

    cob64 -g -x -t -oHELLO HELLO.o

    Thanks

  • I don't reproduce the behaviour you describe...

    From the 1st picture in this notes, I would see the OS as being Linux.

    What MF product ( including update level ) is being used?

    I would think it's better now to raise an incident by Customer Care ...

    FYI. My tests were run on Red Hat ...

    Regards

    Yvon

  • Thank you, Yvon

    Don't worry about it,  I figure out how to turn off -U in Eclipse GUI


    checked "Error on undefined symbol" , it turns off -U flag.

    Thank you again.