/xmake-skills:xmake-link-orderfrom xmake-skills
Fixes linker errors from symbol-order or circular-dependency issues in static libraries using Xmake's add_linkorders, add_linkgroups, whole-archive, and weak linking. Covers macOS, Linux, and MSVC specifics.
Ships in xmake-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
When multiple static libraries depend on each other, order matters to the linker. Xmake gives you three knobs to fix order-related link errors without hand-crafting -Wl,... flags:
add_linkorders — declare that library A must come before library B on the command line.add_linkgroups — wrap a set of libraries in --start-group/--end-group (Linux) or the equivalent so the linker resolves circular references.whole_archive = true option on add_linkgroups — force-include every object, even ones that look unreferenced (plugin registration, static initializers).A static library is a collection of object files. The GNU linker (and most others) resolves symbols in a single left-to-right pass: when it sees -lfoo, it picks up objects that satisfy currently-undefined symbols. Anything not needed yet is discarded.
That causes two common bugs:
-lbar -lfoo where bar depends on foo → undefined symbols from bar, because foo was consumed before bar needed it.foo calls into bar and bar calls into foo → impossible with one-pass linking.add_linkorders — fix ordertarget("app")
set_kind("binary")
add_files("src/main.cpp")
add_deps("foo", "bar", "baz")
add_linkorders("bar", "foo") -- bar depends on foo → bar first, then foo
add_linkorders("baz", "foo", "bar")
add_linkorders(A, B) means A must appear before B on the linker command line (-lA ... -lB). List the dependents before their dependencies. Multiple calls accumulate.
Xmake performs a topo-sort over the declared orders and emits the final link line. If you declare a cycle, xmake raises at configure time.
add_links tootarget("app")
add_links("foo", "bar", "baz")
add_linkorders("bar", "foo")
Works for both library dependencies (add_deps) and raw links (add_links / add_syslinks).
add_linkgroups — group libraries for circular depstarget("app")
set_kind("binary")
add_files("src/main.cpp")
add_linkgroups("foo", "bar", {group = true})
Emits:
-Wl,--start-group -lfoo -lbar -Wl,--end-group
On Linux/MinGW GNU ld. macOS ld64 and Windows link.exe handle circular references differently — xmake normalizes the behavior.
Use when:
foo.a and bar.a mutually reference each other's symbols.-lfoo -lbar -lfoo) — add_linkgroups is the clean fix.target("plugin_host")
set_kind("binary")
add_files("src/main.cpp")
add_linkgroups("plugin_a", "plugin_b", {whole_archive = true})
Emits:
-Wl,--whole-archive -lplugin_a -lplugin_b -Wl,--no-whole-archive -- Linux
-Wl,-force_load,<path-to-plugin_a.a> -- macOS
/WHOLEARCHIVE:plugin_a.lib -- MSVC
Every object in those archives is pulled in — even ones with no outside references. Needed for:
register("name", factory) and there's no other reference.__attribute__((constructor)), __attribute__((section("...")))).target("app")
set_kind("binary")
add_files("src/main.cpp")
-- regular link deps, in order
add_deps("core", "utils")
add_linkorders("core", "utils")
-- circularly-dependent math libs, grouped
add_linkgroups("math_core", "math_ext", {group = true})
-- plugin archives, whole-linked
add_linkgroups("plugin_json", "plugin_yaml", {whole_archive = true})
Xmake arranges these so core utils come first (topo order), then the grouped math libs, then the plugin whole-archives. Run xmake -v to see the final link command.
All four features work natively — --start-group/--end-group, --whole-archive/--no-whole-archive.
--start-group is a no-op (Apple linker resolves multi-pass by default), so add_linkgroups(..., {group = true}) is cheap but unnecessary for circular deps on macOS.--whole-archive maps to -force_load <path>. Xmake resolves the archive path automatically when you use add_linkgroups(..., {whole_archive = true})./WHOLEARCHIVE:libname.lib. Xmake handles it.add_linkorders still works for cases where it matters.xmake -v # show actual link command
xmake -vD 2>&1 | grep -A5 linking
xmake --rebuild # force re-link
Classic symptoms → fix:
| Symptom | Fix |
|---|---|
undefined reference to 'bar_func' and bar is linked | add_linkorders("dependent", "bar") |
undefined reference in both A and B (both are linked) | add_linkgroups("A", "B", {group = true}) |
Plugin registers at runtime but factory_not_found | add_linkgroups("plugin_a", {whole_archive = true}) |
| Works on macOS, fails on Linux | Likely order — Linux GNU ld is stricter |
Works with --start-group manually, clean it up | Use add_linkgroups(..., {group = true}) |
foo and bar are mutually dependent, maybe they should be one target..so/.dll don't get stripped — dlopen/LoadLibrary loads them wholesale.set_kind("object") + add_files. Object libraries sidestep archive strip-off rules: object files are always fully linked.add_linkorders cycle. Raises at configure. Check the declared pairs for a cycle.whole_archive bloats the binary. Every object goes in — even test/debug helpers you never wanted. Split the archive before whole-loading.-force_load needs absolute paths. Xmake fills them in; if you build the flags by hand, you must pass the full path./WHOLEARCHIVE needs the library's base name. Matching is case-insensitive on Windows, case-sensitive on Linux — stick to lowercase.add_linkorders / add_linkgroups operate on named libraries (from add_deps / add_links / add_syslinks). For raw -Wl,... flags, fall back to add_ldflags.add_links / add_syslinks basics → xmake-targets--sdk/--cross) → xmake-cross-compilationxmake-rulesxmake-troubleshootingWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub xmake-io/xmake-skills --plugin xmake-skills58 skills in this plugin
/xmake-addon-developmentUse when writing an Xmake addon — the `addon.lua` manifest, the payload layout (plugins/rules/toolchains/modules/includes/templates), `@self` references, shipping package definitions with an addon, `add_globalmodules`, testing it locally, and publishing it to xmake-repo as an `addon` kind package./xmake-addonsUse when installing or using an Xmake addon — `xmake addon --install/--list/--remove/--upgrade/--search`, declaring `add_addons(...)` in a project, and referencing addon payloads with `@addon/<name>/<rule>`, `@addon.<name>.<module>` or `@self`. For writing and publishing one, see xmake-addon-development./xmake-async-jobsUse when running parallel / async work inside xmake scripts — `async.runjobs` for parallel job execution, `async.jobgraph` (DAG) for dependency-ordered jobs, `async.jobpool` (tree structure), `core.base.scheduler` coroutine scheduling, semaphores, and `on_build_files(..., {jobgraph = true})` in rules. For running external compile jobs faster, see `xmake-build-optimization`.Other plugins' skills for the same job