How to call the externel C function in IR

Hello everyone. I want to call the function in the Dynamic Shared lib, do you know what code in python can do this? Thank you very much!

Hi @benjixu,

The following snippet of code might give you some directions.

from numba import njit
from numba.core import types, typing
from llvmlite import bindings


# calls hypot from libm
c_func_name = 'hypot'
return_type = types.float64
argty = types.float64
c_sig = typing.signature(return_type, argty)
c_hypot = types.ExternalFunction(c_func_name, c_sig)

def example(arg):
    return c_hypot(arg)


@guilherme Thank you, this is very useful! Would it be worth adding such a snippet to the official documentation?

Sure, I can send a PR including this.

1 Like