opensourcecobol / Open-COBOL-ESQL

Open Cobol ESQL (ocesql) is an open-source Embedded SQL pre-compiler and run-time library designed for COBOL applications which access an open-source database.
https://www.osscons.jp/osscobol/
GNU Lesser General Public License v3.0
50 stars 24 forks source link

Intallation fails on Ubuntu #36

Open yutaro-sakamoto opened 2 years ago

yutaro-sakamoto commented 2 years ago

A sample program INSERTTBL in sample/ directory does not work on Ubuntu.

$ ocesql INSERTTBL.cbl INSERTTBL.cob
$ cobc -m -locesql INSERTTBL.cob
$ cobcrun INSERTTBL
*** INSERTTBL STARTED ***
libcob: Cannot find module 'OCESQLConnect'

In order to execute INSERTTBL, it is necessary to set the environment variable LD_PRELOAD to /usr/local/lib/libocesql.so

$ ocesql INSERTTBL.cbl INSERTTBL.cob
$ cobc -m -locesql INSERTTBL.cob
$ LD_PRELOAD=/usr/local/lib/libocesql.so cobcrun INSERTTBL

This problem is probably caused by an incorrect configuration of libocesql.so The following Dockerfile describes the full installation process on Ubuntu.

FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update

RUN apt-get install -y build-essential libncurses5 libncurses5-dev libgmp-dev bison flex gettext automake autoconf git
RUN apt-get install -y libpq-dev

RUN cd /root && git clone https://github.com/opensourcecobol/opensource-cobol.git

RUN cd /root/opensource-cobol/vbisam &&\
    ./configure --prefix=/usr/ &&\
    make &&\
    make install &&\
    cd ../ &&\
    ./configure --prefix=/usr/ --with-vbisam &&\
    make &&\
    make install

ADD https://github.com/opensourcecobol/Open-COBOL-ESQL/archive/refs/tags/v1.2.tar.gz /root/Open-COBOL-ESQL-1.2.tar.gz
RUN cd /root &&\
    tar zxvf Open-COBOL-ESQL-1.2.tar.gz &&\
    cd Open-COBOL-ESQL-1.2 &&\
    ./configure &&\
    C_INCLUDE_PATH=/usr/include/postgresql/ make &&\
    make install

RUN cd /root/Open-COBOL-ESQL-1.2/sample &&\
    cp ../copy/* . &&\
    ocesql INSERTTBL.cbl INSERTTBL.cob &&\
    cobc -m -locesql INSERTTBL.cob  &&\
    LD_PRELOAD=/usr/local/lib/libocesql.so cobcrun INSERTTBL

ENTRYPOINT ["/bin/bash"]
yutaro-sakamoto commented 2 years ago

It seems difficult to solve this issue. I added note to README.

GitMensch commented 2 years ago

LD_PRELOAD is a quite bad hack, with that README note people will likely export it which commonly breaks something and tells the dynamic link loader to do this for every executable. The issue is that libcob does not find the module, very likely because the actual CALL is a dynamic one and/or the dynamic linker removed the "unused" library.

To work around this each of the following solutions should work;

... or: use COB_PRE_LOAD to load the library, or relink libcob/cobcrun to have the library linked with the -Wl,--no-as-needed option.

yutaro-sakamoto commented 2 years ago

I removed the description of LD_PRELOAD in README and created a new wiki page for Ubuntu users. I will fix this issue in the future.