As explained in the @cfunction documentation, the @cfunction macro evaluates its arguments in global scope. If you want to use a local function, you need to interpolate it with $.
(It is more efficient to use a global function here. If you need to pass local data, a well-written C library should generally accept a void* to data in addition to the function library, to pass data re-entrantly through to the function pointer at the call site.)