Problems statically linking flecs library into module

Godot Version

4.3 built from source via github



I’m trying to link a static library into a module as shown here:

I’ve follow the steps as closely as a I can with the exception that I’m on windows, and the library I’m linking is flecs (GitHub - SanderMertens/flecs: A fast entity component system (ECS) for C & C++). This meant I built the library via visual studio’s makefile handling and then dropped the entire folder into a module (/modules/test_module/flecs). I set the SCsub file as follows to account for lib handling on windows:

# SCsub
env.add_source_files(env.modules_sources, "*.cpp")
# Note I used a specific file name due to:

This seems to find the code and .lib ok but when I include flecs.h in a cpp file it fails to build godot with a linker error and a bunch of (probably related) linker warnings:

1>LINK : warning LNK4217: symbol 'abort' defined in 'libucrt.lib(abort.obj)' is imported by 'flecs_static.lib(deserialize.c.obj)' in function 'flecs_binary_expr_do'
1>LINK : warning LNK4217: symbol 'atol' defined in 'libucrt.lib(atox.obj)' is imported by 'flecs_static.lib(cursor.c.obj)' in function 'ecs_meta_set_string'

...about 150 more instances of LNK4217...

1>flecs_static.lib(plecs.c.obj) : error LNK2019: unresolved external symbol __imp_rewind referenced in function flecs_load_from_file
1>bin\ : fatal error LNK1120: 1 unresolved externals

I’m useless with build systems and makefiles but from reading around, the warnings are potentially a conflicting version of those functions in the static library vs in godot’s build. The error seems to be a completely missing function flecs needs, but I don’t understand make projects or libs enough to know what more to look into.

Note I tried running the exact same build of the lib against a cpp console app and it worked correctly, so I’m guessing it’s some interaction between Godot and Flecs.

Anyone got any idea what I’m doing wrong here?

Hey quick update that I got a solution to this. Sadly this won’t actually solve static library specific issues if you’ve found this on google, as I took a different route.

(For anyone stuck on a .lib with an error similar to my original one, I’d recommend checking out the /NODEFAULTLIB compiler flag. That was what I was working on when I figured the following out.)

After re-reading the flecs quickstart guide I realised I could use the flecs library without a .lib by just dropping flecs.h and flecs.c into the module, and building with scons like so:

# SCsub
module_env = env.Clone()
module_env.add_source_files(env.modules_sources, "*.cpp")
module_env.add_source_files(env.modules_sources, "flecs/flecs.c")


This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.