If you use @compile_fun on a function that references other functions defined LATER in the code, you will end up with a NameError. Indeed in that case the names appear in func.__code__.co_names but are not yet present in the eval dictionaries (globals(), locals()).
There is no easy workaround, the best is probably to create your functions in the right order.
See also https://stackoverflow.com/questions/45147260/what-is-co-names