Mentions légales du service

Skip to content

The way to use scotch from python

I'd like to cross-report an issue from MacPort's https://trac.macports.org/ticket/67077 to upstream because I think it should be addressed here.

The scope: a user asked to link libscotch.dylib against libscotcherr.dylib to be able to use it from python via CDLL like he can use it on Debian for example.

On the Debian side I have:

Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import *
>>> CDLL('/usr/lib/x86_64-linux-gnu/libscotch-7.0.3.so')
<CDLL '/usr/lib/x86_64-linux-gnu/libscotch-7.0.3.so', handle 1774080 at 0x7f40c63feb90>
>>> 

and it works because libscotch-7.0.3.so is linked against libscotcherr.so, which means all the symbols are here.

On MacPorts, I follow the current cmake build and this trick doesn't work:

Python 3.9.16 (main, Dec  7 2022, 02:41:07) 
[Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import *
>>> CDLL('/opt/local/lib/libscotch.dylib')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/opt/local/lib/libscotch.dylib, 0x0006): symbol not found in flat namespace (_SCOTCH_errorPrint)
>>> 

I can create a wrapper that links two libraries together like this:

√ /tmp % clang -shared -L/opt/local/lib -lscotch -lscotcherr -o wscotch.dylib    
√ /tmp % python3
Python 3.9.16 (main, Dec  7 2022, 02:41:07) 
[Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from ctypes import *
>>> CDLL('/tmp/wscotch.dylib')
<CDLL '/tmp/wscotch.dylib', handle 213934560 at 0x10a0837f0>
>>>

I could ship it as part of the MacPorts installation, but that seems pretty wired. Isn't it?