Menu

Calling GNUCobol from Java

Anonymous
2015-09-09
2021-07-15
<< < 1 2 (Page 2 of 2)
  • Simon Sobisch

    Simon Sobisch - 2016-01-18

    Just a note if you ever want to compile that much modules into a single dynamically linked library:
    Compile each one with cobc -c (resulting in an assembled, but not linked file, in most cases prog.o) and link the final combined one with cobc -b *.o. This way you have to only recompile changed modules afterwards, not the complete application.

    For the actual JAVA-part I'd do what Bill already suggested: have less as possible "external" entry points (you can code a caller which you pass the program to CALL along with the parameters) and leave all the other (existing) COBOL modules as a single file.

    Simon

     
  • Brian Tiffin

    Brian Tiffin - 2016-01-18

    But, unless you tell me not to, Gary, I'd like to include that listing in the FAQ as Simon pointed out. Looks worthy of sharing.

    Cheers,
    Brian

     

    Last edit: Brian Tiffin 2016-01-18
    • Gary Cowell

      Gary Cowell - 2016-01-18

      Sure Brian, go ahead.

       
  • Oscar

    Oscar - 2016-01-18

    creating one cobol stub program as an interface to your 3,500 cobol program which will call other modules based on fuction code that can help.

     

    Last edit: Oscar 2016-01-18
  • Gary Cowell

    Gary Cowell - 2016-01-18

    The COBOL programs come out of a program generator. So, the answer is "yes and no". I'll check out the linking options for the shared object, thanks.

     
  • Anonymous

    Anonymous - 2018-08-27

    Hi All,

    I am very new to COBOL and everything and was wondering if you can help me understand if I need any specific pre-requisites or COBOL related software to make Garry's program work on my Local?

    I am good with JAVA but couldn't understand if anything else is required to execute .cbl file using above program as I get below exception:

    subtest Exceptionjava.lang.UnsatisfiedLinkError: Unable to load library 'cobsubtest': The specified module could not be found.

     
    • Simon Sobisch

      Simon Sobisch - 2018-08-27

      As you need javac to comple .java to .class (and maybe creating a jar/exe whatever later) you'll need cobc to compile the execute.cbl to an object file or shared object or C library.

      Actually Gary had shown this as

      $ javac -classpath ./jna-4.2.1.jar jnacob.java
      $ cobc -o libcobsubtest.so cobsubtest.cbl
      $ cobc -o libcobsubtest2.so cobsubtest2.cbl
      $ java -classpath ./jna-4.2.1.jar:. jnacob
      

      For a summary of this thread see https://open-cobol.sourceforge.io/faq/index.html#java-native-access

      cobc is the GnuCOBOL compiler executable, so yes: you'll need to have GnuCOBOL installed to follow this examples.

      A summary about ways to do this can be found at https://open-cobol.sourceforge.io/faq/index.html#how-do-i-install-gnucobol - in case you have any issues give the search in the discussion boards a short try and post a new topic if you still have questions.

       

      Last edit: Simon Sobisch 2018-08-27
  • thomas

    thomas - 2019-09-04

    I was trying to call cobol from java using JNA, i used the same example demostrated here but i am getting this error

    Libcob Exceptionjava.lang.UnsatisfiedLinkError: Unable to load library 'cob': Native library (win32-x86-64/cob.dll) not found in resource path
    ([file:/C:/Users/XXXXX/eclipse-workspace/first%20project/, file:/C:/Users/XXXXX/eclipse-workspace/first%20project/jna-4.5.1.jar])

    subtest Exceptionjava.lang.UnsatisfiedLinkError: Unable to load library 'cobsubtest': Native library (win32-x86-64/cobsubtest.dll) not found in resource path
    ([file:/C:/Users/XXXXX/eclipse-workspace/first%20project/, file:/C:/Users/XXXXX/eclipse-workspace/first%20project/jna-4.5.1.jar])

    then i changed the library "cob" to "libcob-4" because there is no cob.dll nor libcob.dll.

    After that i get below error now i don't know what is wrong please help.

    "Libcob Exceptionjava.lang.UnsatisfiedLinkError: %1 is not a valid Win32 application."

    Microsoft Windows [Version 6.1.7601]
    Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
    
    C:\Users\XXXXXXXX>cobc -i
    cobc (GnuCOBOL) 3.1-dev.0
    Copyright (C) 2019 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward Hart
    Built     Sep 01 2019 23:33:31
    Packaged  Aug 28 2019 17:45:18 UTC
    C version (MinGW) "6.3.0"
    
    build information
    build environment        : i686-pc-mingw32
    CC                       : gcc
    C version                : (MinGW) "6.3.0"
    CPPFLAGS                 : -I/mingw/include
    CFLAGS                   : -O2 -pipe -finline-functions -fsigned-char
                               -Wall -Wwrite-strings -Wmissing-prototypes
                               -Wno-format-y2k -U_FORTIFY_SOURCE
    LD                       : c:/gc30x-build/mingw/mingw32/bin/ld.exe
    LDFLAGS                  :
    
    GnuCOBOL information
    COB_CC                   : gcc
    COB_CFLAGS               : -I/mingw/include -Wno-unused -fsigned-char
                               -Wno-pointer-sign -I/mingw/include -pipe
    COB_LDFLAGS              :
    COB_LIBS                 : -L/mingw/lib -lcob
    COB_CONFIG_DIR           : /mingw/share/gnucobol/config
      env: COB_CONFIG_DIR    : C:\GnuCOBOL\config
    COB_COPY_DIR             : /mingw/share/gnucobol/copy
      env: COB_COPY_DIR      : C:\GnuCOBOL\copy
    COB_MSG_FORMAT           : GCC
    COB_OBJECT_EXT           : o
    COB_MODULE_EXT           : dll
    COB_EXE_EXT              : .exe
    64bit-mode               : no
    BINARY-C-LONG            : 4 bytes
    endianness               : little-endian
    native EBCDIC            : no
    extended screen I/O      : pdcurses
    variable file format     : 0
    sequential file handler  : built-in
    ISAM file handler        : VBISAM
    mathematical library     : GMP
    XML library              : disabled
    JSON library             : disabled
    
     

    Last edit: thomas 2019-09-04
    • Simon Sobisch

      Simon Sobisch - 2019-09-04

      I guess java --version shows "64-Bit Server VM" correct (the initial call to "cob" searched for a 64bit version of the dll)?
      You can only call to JNA for system libraries that share the same architecture and your GnuCOBOL seems 32bit. So either use a 32bit version of java (you can setup multiple java environments in eclipse) or use a 64bit version of GnuCOBOL (and have the modules compiled as 64bit with the same compiler).

       
  • thomas

    thomas - 2019-09-05

    Thanks Simon, i am now using 32 bit java and it is working as expected.

     
  • Anonymous

    Anonymous - 2021-07-12

    Hi,
    I am trying to run jnacob class , using the example but I am getting this error:

    java -classpath ./jna-4.2.1.jar; jnacob

    Libcob Exceptionjava.lang.UnsatisfiedLinkError: Unable to load library 'cob': Native library (win32-x86/cob.dll) not found in resource path ([file:/D:/Cobol/javacobol/jna-4.2.1.jar, file:/D:/Cobol/javacobol/])
    subtest Exceptionjava.lang.UnsatisfiedLinkError: Unable to load library 'cobsubtest': Native library (win32-x86/cobsubtest.dll) not found in resource path ([file:/D:/Cobol/javacobol/jna-4.2.1.jar, file:/D:/Cobol/javacobol/])

     
  • Anonymous

    Anonymous - 2021-07-12

    I did some changes, now I have this:

    D:\Cobol\javacobol>java -cp jna-5.8.0.jar; jnacob
    subtest Exceptionjava.lang.UnsatisfiedLinkError: Unable to load library 'cobsubtest':
    The specified module could not be found.

    The specified module could not be found.

    The specified module could not be found.

    Native library (win32-x86/cobsubtest.dll) not found in resource path ([file:/D:/Cobol/javacobol/jna-5.8.0.jar, file:/D:/Cobol/javacobol/])

    I am using:
    C:\Program Files (x86)\Java\jdk1.8.0_291\bin

    cobc (GnuCOBOL) 3.2-dev.0
    Copyright (C) 2021 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
    This is free software; see the source for copying conditions.  There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    Written by Keisuke Nishida, Roger While, Ron Norman, Simon Sobisch, Edward Hart
    Built     Jul 07 2021 21:51:20
    Packaged  Jul 07 2021 11:11:20 UTC
    C version (MinGW) "9.2.0"
    
    build information
    build environment        : i686-pc-mingw32
    CC                       : gcc
    C version                : (MinGW) "9.2.0"
    CPPFLAGS                 :
    CFLAGS                   : -O2 -pipe -finline-functions -fsigned-char
                               -Wall -Wwrite-strings -Wmissing-prototypes
                               -Wno-format-y2k
    LD                       : c:/mingw/mingw32/bin/ld.exe
    LDFLAGS                  :
    
    GnuCOBOL information
    COB_CC                   : gcc
    COB_CFLAGS               : -pipe -I/usr/local/include -Wno-unused
                               -fsigned-char -Wno-pointer-sign
    COB_DEBUG_FLAGS          : -ggdb3 -fasynchronous-unwind-tables
    COB_LDFLAGS              :
    COB_LIBS                 : -L/usr/local/lib -lcob -lm
    COB_CONFIG_DIR           : C:/MinGW/msys/1.0/local/share/gnucobol/config
      env: COB_CONFIG_DIR    : D:\gnucobol\config
    COB_COPY_DIR             : C:/MinGW/msys/1.0/local/share/gnucobol/copy
    COB_MSG_FORMAT           : GCC
    COB_OBJECT_EXT           : o
    COB_MODULE_EXT           : dll
    COB_EXE_EXT              : .exe
    64bit-mode               : no
    BINARY-C-LONG            : 4 bytes
    endianness               : little-endian
    native EBCDIC            : no
    extended screen I/O      : pdcurses
    variable file format     : 0
    sequential file handler  : built-in
    indexed file handler     : BDB
    mathematical library     : GMP
    XML library              : disabled
    JSON library             : cjson
    
     
    • Simon Sobisch

      Simon Sobisch - 2021-07-12

      I'm not sure which jnacob you exactly use, in any case: for being able to load GnuCOBOL you have to have the setup as you have shown.

      As you seem to want to run COBOL modules: test with cobcrun first (for example you likely have to adjustCOB_LIBRARY_PATH to include the place where the COBOL modules reside).

       
  • Anonymous

    Anonymous - 2021-07-15

    I found out the problem, on windows you should run:
    cobc -o libcobsubtest.dll cobsubtest.cbl

    It worked!

     
    👍
    1
<< < 1 2 (Page 2 of 2)

Anonymous
Anonymous

Add attachments
Cancel