target_link_libraries #802
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
✍🏼 Dear Diary,
I ran into this problem when trying to build
obs-moqwherelibmoqwas not ending up in the finalobs-moq.sofile 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 configurationsCMake'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}")