Skip to content

Commit

Permalink
ekf_lib_init
Browse files Browse the repository at this point in the history
  • Loading branch information
fredyshox committed Nov 19, 2023
1 parent ba43c47 commit 53f8d1f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
9 changes: 9 additions & 0 deletions rednose/helpers/ekf.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,12 @@ struct EKF {
std::unordered_map<std::string, void (*)(double)> sets = {};
std::unordered_map<std::string, extra_routine_t> extra_routines = {};
};

#define ekf_lib_init(ekf) \
extern "C" void* ekf_get() { \
return (void*) &ekf; \
} \
extern void __attribute__((weak)) ekf_register(const EKF* ptr); \
static void __attribute__((constructor)) do_ekf_init_ ## ekf(void) { \
if (ekf_register) ekf_register(&ekf); \
}
6 changes: 1 addition & 5 deletions rednose/helpers/ekf_sym.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,7 @@ def gen_code(folder, name, f_sym, dt_sym, x_sym, obs_eqs, dim_x, dim_err, eskf_p
post_code += f" {{ \"{f}\", {name}_{f} }},\n"
post_code += " },\n"
post_code += "};\n\n"
post_code += "extern \"C\" {\n"
post_code += " void* ekf_get() {\n"
post_code += f" return (void*)&{name};\n"
post_code += " }\n"
post_code += "}\n\n"
post_code += f"ekf_lib_init({name})\n"

# merge code blocks
header += "}"
Expand Down
7 changes: 6 additions & 1 deletion site_scons/site_tools/rednose_filter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import platform

from SCons.Script import Dir, File, Glob


Expand All @@ -23,7 +25,10 @@ def __init__(self, base_py_deps, base_cc_deps):
class CompileFilterMethod(BaseRednoseCompileMethod):
def __call__(self, env, target, filter_gen_script, output_dir, extra_gen_artifacts=[], gen_script_deps=[]):
objects = compile_single_filter(env, target, filter_gen_script, output_dir, extra_gen_artifacts, self.base_py_deps + gen_script_deps)
lib_target = env.SharedLibrary(f'{output_dir}/{target}', [self.base_cc_deps, objects])
linker_flags = env.get('LINKFLAGS', [])
if platform.system() == "Darwin":
linker_flags = ['-undefined dynamic_lookup']
lib_target = env.SharedLibrary(f'{output_dir}/{target}', [self.base_cc_deps, objects], LINKFLAGS=linker_flags)

return lib_target

Expand Down

0 comments on commit 53f8d1f

Please sign in to comment.