I cannot fix this error. build.sh is trying to create a shared library but it fails:
~/Desktop/deepseek$ ./build.sh
Building Haskell shared library...
Loaded package environment from /home/success/.ghc/x86_64-linux-9.6.7/environments/default
[2 of 2] Linking libminimal.so [Flags changed]
Build successful! Running Python test...
----------------------------------------
Traceback (most recent call last):
File "/home/success/Desktop/deepseek/test_minimal.py", line 5, in <module>
lib = ctypes.CDLL('./libminimal.so')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/ctypes/__init__.py", line 379, in __init__
self._handle = _dlopen(self._name, mode)
^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: /home/success/.ghcup/ghc/9.6.7/lib/ghc-9.6.7/lib/../lib/x86_64-linux-ghc-9.6.7/libHSghc-prim-0.10.0-ghc9.6.7.so: undefined symbol: stg_gc_unpt_r1
build.sh
#!/bin/bash
echo "Building Haskell shared library..."
# Compile Haskell to shared library
ghc -O2 -dynamic -shared -fPIC -o libminimal.so Minimal.hs
if [ $? -eq 0 ]; then
echo "Build successful! Running Python test..."
echo "----------------------------------------"
python3 test_minimal.py
else
echo "Build failed!"
exit 1
fi
Minimal.hs
{-# LANGUAGE ForeignFunctionInterface #-}
module Minimal where
import Foreign.C.Types
import Foreign.Ptr
-- Simple function that receives a Python module and prints confirmation
foreign export ccall receivePythonModule :: Ptr () -> IO ()
receivePythonModule :: Ptr () -> IO ()
receivePythonModule modulePtr = do
putStrLn "Haskell: Received Python module!"
putStrLn "Haskell: This is where you'd process the module..."
test_minimal.py
#!/usr/bin/env python3
import ctypes, sys, types
# Load the shared library
lib = ctypes.CDLL('./libminimal.so')
# Define the function signature
lib.receivePythonModule.argtypes = [ctypes.c_void_p]
lib.receivePythonModule.restype = None
def pass_module_to_haskell():
# Create a simple Python module
test_module = types.ModuleType('test_module')
test_module.some_value = 42
test_module.some_function = lambda x: x * 2
module_ptr = ctypes.c_void_p(id(test_module))
lib.receivePythonModule(module_ptr)
if __name__ == "__main__":
pass_module_to_haskell()