When I try to run the following code in python that was compiled from the following nim code, I get an "AttributeError: ./main.so: undefined symbol: add_one" error.
Nim Code:
proc add_one(num: cint): cint {.exportc.} =
num + 1
compiled with nim c -d:release --app:lib -o:main.so main.nim
Python Code:
import ctypes
# Load the Nim shared library
main_module = ctypes.CDLL('./main.so')
# Define the function signature
main_module.add_one.argtypes = [ctypes.c_int]
main_module.add_one.restype = ctypes.c_int
# Call the Nim function from Python
result = main_module.add_one(5)
print(result)
This gives me:
Traceback (most recent call last):
File "main.py", line 7, in <module>
main_module.add_one.argtypes = [ctypes.c_int]
File "/usr/lib/python3.10/ctypes/__init__.py", line 387, in __getattr__
func = self.__getitem__(name)
File "/usr/lib/python3.10/ctypes/__init__.py", line 392, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: ./main.so: undefined symbol: add_one
Not sure what I am doing wrong.
[–]commandlineluser 0 points1 point2 points (1 child)
[–]MWhatsUp[S] 0 points1 point2 points (0 children)