ibmdb / ruby-ibmdb

Rails Adapter/Ruby driver for IBM DB2 and IBM Informix
43 stars 49 forks source link

Error: extconf failure: Unable to locate libdb2.so/a #154

Closed wisenrico closed 1 year ago

wisenrico commented 1 year ago

I am facing this blocking error while trying to install the ibm_db gem or trying to run rake command with the driver:

extconf failure: Unable to locate libdb2.so/a under /Users/xxx/ruby-ibmdb-5.4.1/IBM_DB_Driver/../lib/clidriver/lib

How to reproduce

Environment

MacBook Pro M1 macOS 13.4 (22F66)

Output

/Users/[User]/.rbenv/versions/3.2.1/bin/ruby extconf.rb
Detected 64-bit Ruby

Detected platform - MacOS darwin64
extconf.rb:95: warning: already initialized constant DOWNLOADLINK
extconf.rb:45: warning: previous definition of DOWNLOADLINK was here
Environment variable IBM_DB_HOME is not set. Downloading and setting up the DB2 client driver
extconf.rb:183: warning: already initialized constant IBM_DB_HOME
extconf.rb:21: warning: previous definition of IBM_DB_HOME was here
extconf.rb:185: warning: already initialized constant IBM_DB_INCLUDE
extconf.rb:166: warning: previous definition of IBM_DB_INCLUDE was here
extconf.rb:186: warning: already initialized constant IBM_DB_LIB
extconf.rb:167: warning: previous definition of IBM_DB_LIB was here
creating gil_release_version.h
creating unicode_support_version.h
checking for SQLConnect() in -ldb2... no
checking for SQLConnect() in -ldb2... no
 extconf failure: Unable to locate libdb2.so/a under /Users/[User]/ruby-ibmdb-master/IBM_DB_Driver/../lib/clidriver/lib

Follow the steps below and retry

Step 1: - Install IBM DB2 Universal Database Server/Client

step 2: - Set the environment variable IBM_DB_HOME as below

             (assuming bash shell)

             export IBM_DB_HOME=<DB2/IBM_Data_Server_Driver installation directory> #(Eg: export IBM_DB_HOME=/opt/ibm/db2/v10)

step 3: - Retry gem install

*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/Users/[User]/.rbenv/versions/3.2.1/bin/$(RUBY_BASE_NAME)
    --with-IBM_DB-dir
    --without-IBM_DB-dir
    --with-IBM_DB-include
    --without-IBM_DB-include=${IBM_DB-dir}/include
    --with-IBM_DB-lib
    --without-IBM_DB-lib=${IBM_DB-dir}/lib
    --with-db2-dir
    --without-db2-dir
    --with-db2-include
    --without-db2-include=${db2-dir}/include
    --with-db2-lib
    --without-db2-lib=${db2-dir}/lib
    --with-db2lib
    --without-db2lib
    --with-db2lib
    --without-db2lib
rake aborted!
Command failed with status (1): [/Users/[User]/.rbenv/versions/3.2...]
/Users/[User]/ruby-ibmdb-master/IBM_DB_Driver/Rakefile:15:in `block in <top (required)>'
Tasks: TOP => default => test => lib => ibm_db.so => extconf => Makefile
(See full trace by running task with --trace)

Notes

praveen-db2 commented 1 year ago

@wisenrico For above error you may need to set env var as below,

Windows:
set LIB=%IBM_DB_HOME%/lib;%LIB%

AIX:
export LIBPATH=$IBM_DB_HOME/lib:$LIBPATH

MAC:
export DYLD_LIBRARY_PATH=$IBM_DB_HOME/lib:$DYLD_LIBRARY_PATH

Other platforms:
export LD_LIBRARY_PATH=$IBM_DB_HOME/lib:$LD_LIBRARY_PATH
wisenrico commented 1 year ago

Thank you @praveen-db2. I have tried to export the env vars as following:

export IBM_DB_HOME=/Users/[User]/ruby-ibmdb-master/lib/clidriver
export DYLD_LIBRARY_PATH=$IBM_DB_HOME/lib:$DYLD_LIBRARY_PATH

echo $DYLD_LIBRARY_PATH
/Users/[User]/ruby-ibmdb-master/lib/clidriver/lib:/lib:

but I had no luck:

Detected 64-bit Ruby

Detected platform - MacOS darwin64
extconf.rb:95: warning: already initialized constant DOWNLOADLINK
extconf.rb:45: warning: previous definition of DOWNLOADLINK was here
Detected usage of IBM Data Server Driver package. Ensure you have downloaded 64-bit package of IBM_Data_Server_Driver and retry the 'gem install ibm_db' command

creating gil_release_version.h
creating unicode_support_version.h
checking for SQLConnect() in -ldb2... no
checking for SQLConnect() in -ldb2... no
 extconf failure: Unable to locate libdb2.so/a under /Users/[User]/ruby-ibmdb-master/lib/clidriver/lib

Follow the steps below and retry

Step 1: - Install IBM DB2 Universal Database Server/Client

step 2: - Set the environment variable IBM_DB_HOME as below

             (assuming bash shell)

             export IBM_DB_HOME=<DB2/IBM_Data_Server_Driver installation directory> #(Eg: export IBM_DB_HOME=/opt/ibm/db2/v10)

step 3: - Retry gem install

*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

My clidriver directory looks like this:

image
praveen-db2 commented 1 year ago

@wisenrico do you have gcc installed, if installed check if u have permission for gcc and also make sure developer tools installed.

Unset IBM_DB_HOME and DYLD_LIBRARY_PATH before installing ibm_db as you are not installing clidriver manually

praveen-db2 commented 1 year ago

@wisenrico i see you trying to build from IBM_DB_DRIVER dir, if you want to build here, you need to manually install clidriver and set IBM_DB_HOME and DYLD_LIBRARY_PATH, and then try building IBM_DB_DRIVER.

If you do build and install from IBM_DB_Adapter , clidriver will be auto downloaded and installed., so no need to set IBM_DB_HOME and DYLD_LIBRARY_PATH before build and install of gem.

wisenrico commented 1 year ago

I tried both solutions but none of them work.

When trying to install from adapter I have the same problem:

echo $DYLD_LIBRARY_PATH

echo $IBM_DB_HOME

~/ruby-ibmdb-5.4.1/IBM_DB_Adapter | gem install ibm_db

Building native extensions. This could take a while...
ERROR:  Error installing ibm_db:
    ERROR: Failed to build gem native extension.

    current directory: /Users/[User]/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/ibm_db-5.4.1/ext
/Users/[User]/.rbenv/versions/3.2.1/bin/ruby -I /Users/[User]/.rbenv/versions/3.2.1/lib/ruby/3.2.0 extconf.rb
extconf.rb:95: warning: already initialized constant DOWNLOADLINK
extconf.rb:45: warning: previous definition of DOWNLOADLINK was here
extconf.rb:183: warning: already initialized constant IBM_DB_HOME
extconf.rb:21: warning: previous definition of IBM_DB_HOME was here
extconf.rb:185: warning: already initialized constant IBM_DB_INCLUDE
extconf.rb:166: warning: previous definition of IBM_DB_INCLUDE was here
extconf.rb:186: warning: already initialized constant IBM_DB_LIB
extconf.rb:167: warning: previous definition of IBM_DB_LIB was here
Detected 64-bit Ruby

Detected platform - MacOS darwin64
Environment variable IBM_DB_HOME is not set. Downloading and setting up the DB2 client driver
creating gil_release_version.h
creating unicode_support_version.h
checking for SQLConnect() in -ldb2... no
checking for SQLConnect() in -ldb2... no
 extconf failure: Unable to locate libdb2.so/a under /Users/[User]/.rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/ibm_db-5.4.1/ext/../lib/clidriver/lib

Follow the steps below and retry

The indicated directory contains:

image
praveen-db2 commented 1 year ago

@wisenrico below are steps i follow to build and install ibm_db driver and adapter from source.

BUILD ibm_db gem  from sources (ibm_db-x.x.x.tar.gz):

    1. mkdir ROR3x  (Assuming I am at home directory.)
       cd ROR3x

       Download source from Github via clone or download tar.gz and untar the same
       https://github.com/ibmdb/ruby-ibmdb

    2.  Build the driver inside ruby-ibmdb/IBM_DB_Adapter/ibm_db:
        gem list                (To list all gems installed, if 'zip' gem not installed install it)
        gem install zip    

        - $ unset IBM_DB_HOME                       (To unset IBM_DB_HOME to nothing before installng ruby ibm_db)
        - $ rm -rf ruby-ibmdb/IBM_DB_Adapter/ibm_db/lib/clidriver*  (Just to remove clidriver if its installed before)
        - $ cd ruby-ibmdb/IBM_DB_Adapter/ibm_db/ext
        - $ rm Makefile ibm_db.so *.log
        - $ ruby extconf.rb
        - $ make       (On Linux)       (This also download and install clidriver from internet and install at ruby_ibmdb/IBM_DB_Adapter/ibm_db/lib)
            (or)
            ridk exec make (On windows)

        Build the ibm_db gem
        - $ rm ../lib/ibm_db.so
        - $ cp ibm_db.so ../lib (Note: ibm_db.so will be generated under ~/ROR3x/ruby-ibmdb/IBM_DB_Adapter/ibm_db/ext/ when 'make' is run. And should be copied to lib dir which is under path ~/ROR3x/ruby-ibmdb/IBM_DB_Adapter/ibm_db/lib)
        - $ cd ..                       (i.e to ~/ROR3x/ruby-ibmdb/IBM_DB_Adapter/ibm_db)
        - $ gem build IBM_DB.gemspec    (This will create gem file ibm_db-5.x.0.gem)

        cd ../../../

        gem install --local ruby-ibmdb/IBM_DB_Adapter/ibm_db/ibm_db-5.x.0.gem
wisenrico commented 1 year ago

I tried again with no success at all. Analyzing the libdb2.dylib file I see that the arm64 architecture is not listed.

/Users/[User]/rbenv/versions/3.2.1/lib/ruby/gems/3.2.0/gems/ibm_db-5.4.1/lib/clidriver/lib/libdb2.dylib: Mach-O 64-bit dynamically linked shared library x86_64

Could this be the issue here? M1 is arm64, not x86_64.

praveen-db2 commented 1 year ago

Sorry clidriver is not supported on arm64 architecture.

bimalkjha commented 1 year ago

@wisenrico You can install x86_64 version (Intel Only version) of ruby on M1 Chip system and then install ibmdb. Thanks.

praveen-db2 commented 1 year ago

@wisenrico can we close this issue ?

wisenrico commented 1 year ago

Yes the issue can be closed.

The workaround I found is to use Docker as host. In this case, I have installed the gem by using platform: linux/amd64 in my docker-compose.yml file.