Repository navigation
Description
I investigated a bit. I downloaded the package from PyPi and ran the installation with setup.py install, using first the system Python version (located in /usr/bin/python3, for me Python 3.8.9) and then the Python version from my virtual environment, Python 3.8.10. Both come to the same following ld: warnings:
> /usr/bin/python3 setup.py install
[...]
50 warnings generated.
clang -bundle -undefined dynamic_lookup -arch arm64 -arch x86_64 -Wl,-headerpad,0x1000 -L/opt/homebrew/opt/openssl@3/lib -I/opt/homebrew/opt/openssl@3/include build/temp.macosx-10.14.6-arm64-3.8/ibm_db.o -Lclidriver/lib -L$ORIGIN/clidriver/lib -ldb2 -o build/lib.macosx-10.14.6-arm64-3.8/ibm_db.cpython-38-darwin.so
ld: warning: directory not found for option '-L$ORIGIN/clidriver/lib'
ld: warning: ignoring file clidriver/lib/libdb2.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
Interestingly, using the system Python passes in two arch commands, one for arm64 and one for x86_64. Using the one from virtual environment does not pass in any arch commands:
/Users/ibmdbtest/.pyenv/versions/3.8.10/bin/python setup.py install
[...]
50 warnings generated.
clang -bundle -undefined dynamic_lookup -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/readline/lib -L/Users/ibmdbtest/.pyenv/versions/3.8.10/lib -L/opt/homebrew/lib -L/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/lib -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/readline/lib -L/Users/ibmdbtest/.pyenv/versions/3.8.10/lib -L/opt/homebrew/lib -L/Library/Developer/CommandLineTools/SDKs/MacOSX12.1.sdk/usr/lib -L/opt/homebrew/opt/openssl@3/lib -I/opt/homebrew/opt/openssl@3/include build/temp.macosx-12.1-arm64-3.8/ibm_db.o -Lclidriver/lib -L/Users/ibmdbtest/Downloads/clidriver/lib -ldb2 -o build/lib.macosx-12.1-arm64-3.8/ibm_db.cpython-38-darwin.so
ld: warning: ignoring file clidriver/lib/libdb2.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
Using the files that result from this build ends up in the same error as experienced by regularly installing the library, the one described by OP of #688:
import ibm_db
E ImportError: dlopen(.../venv/lib/python3.8/site-packages/ibm_db.cpython-38-darwin.so, 0x0002): symbol not found in flat namespace '_SQLAllocHandle'
After reading through everything mentioned there, I also tried to use a manually downloaded clidriver (from here), this does not change the result.
This issue has the same root cause as #688 which was wrongfully closed in my opinion.
Activity
bimalkjha commentedon Jan 8, 2022
@jonathanherdt In your
setup.py installoutput, we can see below warnings, which seems the root cause of this issue:Can you confirm, you have
$ORIGIN/clidriver/libdirectory?If yes, then probably native add-on binary is unable to link with
clidriver/lib/libdb2.dyliband hence error. The symbol_SQLAllocHandleis defined inlibdb2.dyliblibrary.jonathanloske commentedon Jan 9, 2022
Hello @bimalkjha , the directory
$ORIGIN/clidriver/libcannot be found and I do not have such a directory. Still,-Lclidriver/libis also passed in, which can be found, it is on the same level assetup.py. If$ORIGINis supposed to be an environment variable, it is not set:bimalkjha commentedon Jan 9, 2022
@jonathanherdt
$ORIGINis an internal variable ofsetup.pyand$ORIGINshould point to the directory ofsetup.py. It is not a system environment variable. So, as long as you are able to find a directoryclidriver/lib, we are good. In this case, problem should belibdb2.dyliblibrary.jonathanloske commentedon Jan 10, 2022
@bimalkjha Understood.
What's the next step now? Can I help in any way?I understand the next step will be to recompilelibdb2.dylibfor arm64 which I won't be able to do without access to the source code. Please let me know if I can still help in any way.bimalkjha commentedon Jan 15, 2022
@jonathanherdt The problem seems due to use of clang compiler which comes with xcode on macos. If possible, could you try to install gcc version 8.x, set PATH to use the gcc and then try to install ibm_db? Run
gcc --versionpost installation to make sure it is getting picked up and installed properly. Thanks.jonathanloske commentedon Jan 21, 2022
@bimalkjha Will it have to be gcc 8.x? This version does not seem to be installable on the
macOS-arm64architecture, gcc 11.x being the lowest version that is available. I tried with gcc 11 instead and got the following:Again, the errors show that we need
clidriver/lib/libdb2.dylibto be compiled formacOS-arm64. I think this is beyond the scope of thepython-ibmdbproject but I wouldn't know where else to report this so here we are. Any chance we will get a recompiledclidriverfor the Apple Silicon architecture sometime soon?jonathanloske commentedon Jan 24, 2022
Update: I've clicked through the IBM support page and can't move forward because we don't have a Customer number (we only use an instance of DB2 that we didn't set up ourselves). This is therefore my most appropriate way to move this issue forward to you, even though this might not be the fully correct place to address this. If there is any better place to submit my issue, please let me know and I will move the discussion there.
bimalkjha commentedon Jan 28, 2022
@jonathanherdt You should contact the person who set up the Db2 instance or shared the connection info. Db2 server need license unless it is not the Db2 Express-C which is old. So, with license they should have the Db2 support too.
As far as I know, IBM do not support arm-64 architecture officially. Only x64 platforms. So, this behavior is expected as per IBM.
We are just trying by updating the gcc version if it could work as many users are using node ibm_db driver on M1 chip system and they do not face such issues with clidriver, so python ibm_db should also work.
We have requested one M1 chip system for testing and probably next week we'll get it. Then we can try ourselves and try to look deeper.
From your shared output, we see two main linker issues:
python setup.py installcommand. Thanks.jonathanloske commentedon Feb 1, 2022
@bimalkjha Tried with hard setting ORIGIN via
CC=/usr/bin/gcc ORIGIN=/Users/ibmdbtest/Downloads/ibm_db-3.1.0 /Users/ibmdbtest/.pyenv/versions/3.8.10/bin/python setup.py installwhich still producedld: warning: directory not found for option '-L$ORIGIN/clidriver/lib'. The other error I'm not sure how to fix since my guess is that this is the result of the files from the downloaded ODBC CLI.I realized I might have used the wrong gcc, your response made me try out
/usr/bin/gccwhich worked better.It's great to hear that you'll be getting an M1 system, this will help a lot, thank you. 🙏 My guess is that people with node still are not able to use this properly since the latest comment from that issue discussion shows the same
_SQLAllocHandleerror that is the subject of this ticket.Here's my full output:
I tried installing this via
CC=/usr/bin/gcc poetry run pip install ~/Downloads/ibm_db-3.1.0but it still in the end produces the_SQLAllocHandleerror.bimalkjha commentedon Mar 11, 2022
@jonathanherdt Install x64 version of python on M1 chip system and then install ibm_db. You can install this python: https://www.python.org/ftp/python/3.9.10/python-3.9.10-macosx10.9.pkg and verify. Thanks.
amukherjee28 commentedon Mar 11, 2022
After installing the python for intel only the correct binaries are loaded and python ibm_db works fine on M1 chip systems.
The clidriver for mac is also updated to db2_v11.5.6.0
Default CLI driver version
Installing Python for intel
Set DYLD_LIBRARY_PATH
Application run output
Please update the following on M1 chip systems and python driver should work fine.
Thanks
jonathanloske commentedon Mar 14, 2022
This worked but it needed me to again specify an x86-compatible GCC like
CC=/usr/bin/gcc.It will still be very important for our project to get this running without x86 compatibility mode. We are using pyenv and installing an x86-compatible version of Python via pyenv requires all of our other dependencies to run in x86 compatibility mode as well.
Finally, I am very happy and thankful that we have gotten to this point here, an important milestone. 🙏
bimalkjha commentedon Jul 31, 2022
@jonathanherdt If you install
intel-onlyversion of python like https://www.python.org/ftp/python/3.9.13/python-3.9.13-macosx10.9.pkg, you will overcome the dependency of x86. ibm_db works fine with this python. Thanks.