bazelbuild / bazelbuild/rules_apple
Duplicate symbol errors when indirectly linking cc_binary with objc_library
- Dominant language
- Starlark
- Stars
- 593
- Forks
- 334
- Avg merge
- 16h 48m
- Merged PRs (30d)
- 9
Description
I have a project where a `cc_library` depends on `objc_library`. When building an `ios_application` target everything works fine (the actual application is in turn based on `objc_library`).
However, when I try to build a `cc_binary` for macos, which depends on the `cc_library`, the link can not succeed. It appears, that dependencies, common to `cc_library` and its dependent `objc_library` are compiled twice, with different destination prefixes, and then added to the link twice, resulting in failure.
For example:
```
# ... innumerable similar errors skipped
duplicate symbol '_ares_inet_ntop' in:
bazel-out/darwin-dbg/bin/external/com_github_cares_cares/libares.lo(inet_ntop.o)
bazel-out/applebin_macos-darwin_x86_64-dbg-ST-cd2b3b8d4835/bin/external/com_github_cares_cares/libares.lo(inet_ntop.o)
ld: 96 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error in child process '/usr/bin/xcrun'. 1
```
This appears to happen, because `cc_library` and `objc_library` both depend on cares, and cares gets added to link twice (applies to the rest of similar libs the same).
Contributor guide
Research direction
Reproduce the macOS cc_binary build with a cc_library depending on an objc_library, using the dependency setup described in the issue. Inspect the link inputs for the shared cares dependency; done means common dependencies are not compiled or added to the link twice and the target links without duplicate-symbol errors.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100