Search code examples
pythongccdb2

Symbol not found: error while using ibm_db library in Python


I am using Monterey MacOS and Python 3.10. While running this sample code:

from ibm_db import connect
from ibm_db import fetch_assoc
from ibm_db import tables

connection = connect('DATABASE=<DATABASE>;'
                     'HOSTNAME=<HOSTNAME>;'  
                     'PORT=<PORT>;'
                     'PROTOCOL=<PROTOCOL>;'
                     'UID=<UID>;'
                     'PWD=<PWD>;', '', '')

I am getting error:

ImportError: dlopen(../lib/python3.10/site-packages/ibm_db.cpython-310-darwin.so, 0x0002): Symbol not found: (___cxa_throw_bad_array_new_length)
  Referenced from: '../lib/python3.10/site-packages/clidriver/lib/libdb2.dylib'
  Expected in: '/usr/lib/libstdc++.6.dylib'

Followed one of the solutions suggested in SO as:

export DYLD_LIBRARY_PATH=/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/clidriver/lib

but didn't work. Works fine on Windows machine but not working on latest MacOS. Some suggested to place libstdc++.6.0.9.dylib in /usr/lib but can't do because of the permission issues.


Solution

  • I found the solution:

    1. create a virtual environment and copy libstdc++.6.dylib into ../venv/lib/python3.10/site-packages/clidriver/lib folder.

    2. export DYLD_LIBRARY_PATH=../venv/lib/python3.10/site-packages/clidriver/lib:$DYLD_LIBRARY_PATH

    libstdc++.6.dylib can be downloaded from the web.