add extern funcs declaration and casts for cimpiling C++ compiler

There are some function prototype conflictions and missing type casts.