Skip to content

Conversation

@davegullo
Copy link
Contributor

✍🏼 Dear Diary,
I ran into this problem when trying to build obs-moq where libmoq was not ending up in the final obs-moq.so file in Linux. Changing this CMakeLists.txt setting did the trick.

Problem:

When building projects that link against libmoq (like obs-moq), the Rust static library was not being properly linked into the final binary. This resulted in:
Dramatically smaller output files (~310KB instead of ~31MB)
Runtime errors: undefined symbol: moq_origin_consume and other moq API functions

Root Cause:

The original code used:
target_link_options(moq INTERFACE "$<LINK_ONLY:${RUST_LIB}>")

This approach has issues:
target_link_options is not designed for libraries - it's meant for linker flags (like -Wl,--as-needed), not library files
The $<LINK_ONLY:...> generator expression doesn't reliably work with INTERFACE targets in all CMake configurations
CMake's dependency tracking doesn't properly recognize the static library as a link dependency, so it may be silently omitted during the link phase

Solution:

Using target_link_libraries is the canonical CMake approach for linking libraries:
target_link_libraries(moq INTERFACE "${RUST_LIB}")

@davegullo davegullo changed the title fix linker errors which would not include libmoq in the final output target_link_libraries Dec 23, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 23, 2025

Walkthrough

The change modifies the CMake build configuration for the moq target in rs/libmoq/CMakeLists.txt. Specifically, it replaces target_link_options with target_link_libraries to link the Rust library. This substitution changes how the linker processes the dependency—instead of applying it as a direct linker option, it creates an explicit target dependency. As a result, the Rust library will appear after object files in the link command sequence rather than being forced at a specific position. Explanatory comments were added to document this change.

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'target_link_libraries' is too vague and does not clearly convey the main purpose of the change, which is fixing linker errors to include libmoq in final output. Use a more descriptive title that explains the problem being solved, such as 'Fix libmoq linking to prevent undefined symbol errors' or 'Replace target_link_options with target_link_libraries to properly link libmoq'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the problem (libmoq not being linked), root cause (misuse of target_link_options), and solution (switching to target_link_libraries), demonstrating strong alignment with the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 200693d and bf0cb5c.

📒 Files selected for processing (1)
  • rs/libmoq/CMakeLists.txt
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Check
🔇 Additional comments (1)
rs/libmoq/CMakeLists.txt (1)

51-53: Excellent fix for the linker issue!

The change from target_link_options to target_link_libraries is the correct approach. target_link_libraries properly establishes the library dependency and ensures CMake tracks the static library correctly in the link command. The added comments clearly explain the rationale.

The removal of the $<LINK_ONLY:...> generator expression is also appropriate here—for an INTERFACE target, you want the library to propagate to consumers.

Please confirm that this change resolves the original obs-moq build issue on Linux (where binaries were missing the ~31MB Rust library and producing undefined symbol errors).


Comment @coderabbitai help to get the list of available commands and usage tips.

@kixelated
Copy link
Collaborator

idk I don't pretend to understand Cmake.

@kixelated kixelated merged commit 9dec508 into moq-dev:main Dec 23, 2025
1 check passed
@moq-bot moq-bot bot mentioned this pull request Dec 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants