Skip to content

Commit 69eaf35

Browse files
fix(shared_lib): force-load archive members into shared library
Passing libluos_engine.a directly to the linker produced a dylib/so with zero symbols: a static archive is only searched for already- referenced undefined symbols, and the output library starts empty so no archive members are ever pulled in. Use -Wl,--whole-archive / -Wl,--no-whole-archive on Linux and Windows and -Wl,-force_load on macOS so every object in libluos_engine.a is linked into the resulting shared library. Ref: https://stackoverflow.com/questions/77983254/ Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent a568da4 commit 69eaf35

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

src/shared_lib_build.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ def shared_lib(source, target, env):
2222
break
2323

2424
if libPath is not None:
25-
# Convert the luos_engine.a archive to a shared library
25+
# Convert the luos_engine.a archive to a shared library.
26+
# A static archive is only searched for already-referenced symbols, so
27+
# linking it into an otherwise empty shared lib yields zero symbols.
28+
# Force the linker to include every object from the archive.
2629
if (pf.system() == 'Windows'):
27-
env.Execute("gcc -shared -fPIC -o $BUILD_DIR/libluos_engine.dll " + libPath)
30+
env.Execute("gcc -shared -fPIC -o $BUILD_DIR/libluos_engine.dll -Wl,--whole-archive " + libPath + " -Wl,--no-whole-archive")
2831
click.secho("* Luos engine shared library available in " + str(env.subst("$BUILD_DIR")) + "/libluos_engine.dll .", fg="green")
2932
elif (pf.system() == 'Linux'):
30-
env.Execute("gcc -shared -fPIC -o $BUILD_DIR/libluos_engine.so " + libPath)
33+
env.Execute("gcc -shared -fPIC -o $BUILD_DIR/libluos_engine.so -Wl,--whole-archive " + libPath + " -Wl,--no-whole-archive")
3134
click.secho("* Luos engine shared library available in " + str(env.subst("$BUILD_DIR")) + "/libluos_engine.so .", fg="green")
3235
elif (pf.system() == 'Darwin'):
33-
#for networklib in networklibs:
34-
#env.Execute("gcc -v -dynamiclib -install_name $BUILD_DIR/" + os.path.basename(networklib)[0:-10] + "_luos_engine.dylib -o $BUILD_DIR/" + os.path.basename(networklib)[0:-10] + "_luos_engine.dylib " + libPath + " " + networklib)
35-
36-
env.Execute("gcc -v -dynamiclib -fPIC -fvisibility=default -install_name $BUILD_DIR -o $BUILD_DIR/libluos_engine.dylib " + libPath)
36+
env.Execute("gcc -dynamiclib -fPIC -fvisibility=default -install_name $BUILD_DIR -o $BUILD_DIR/libluos_engine.dylib -Wl,-force_load," + libPath)
3737
click.secho("\n")
3838
click.secho("Luos engine shared libraries available in " + str(env.subst("$BUILD_DIR")) + "/ :", underline=True)
3939
for networklib in networklibs:

0 commit comments

Comments
 (0)