bazelbuild / bazelbuild/bazel

"link_extra_lib" does not have any effect if "linkshared = True" on cc_binary

Open
#25,079 2 comments 0 reactions 0 assignees View on GitHub
P3 stale team-Rules-CPP type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

### Description of the bug:

I'm trying to use `link_extra_lib` to link against my C++ runtime environment (a cc_library containing my custom libstdc++.so). This works for regular cc_binaries and cc_tests. However, it does not work for shared libraries, i.e. cc_binary with link_shared=True.

It appears it might be due to this code:
https://github.com/bazelbuild/bazel/blob/56bf54716094bf6b687366d20b577435213681d5/src/main/starlark/builtins_bzl/common/cc/cc_shared_library.bzl#L1107

It's however unclear why this restriction applies. Could this be clarified/fixed?

### Which category does this issue belong to?

C++ Rules

### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

_No response_

### Which operating system are you running Bazel on?

Ubuntu 24.04

### What is the output of `bazel info release`?

release 7.4.1

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse HEAD` ?

```text

```

### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

_No response_

### Have you found anything relevant by searching the web?

Asked on [Slack](https://bazelbuild.slack.com/archives/CGA9QFQ8H/p1737973541827809?thread_ts=1737769527.198369&cid=CGA9QFQ8H) and got the suggestion to file an issue.

### Any other information, logs, or outputs that you want to share?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by inspecting src/main/starlark/builtins_bzl/common/cc/cc_shared_library.bzl around line 1107 and trace how link_extra_lib is handled for cc_binary targets with link_shared=True. Reproduce the behavior on Ubuntu 24.04 with Bazel 7.4.1, then determine whether the restriction is intentional. Done means the behavior is clarified or corrected and verified for shared-library binaries.

Written by the indexing model from the issue text.

Assessment

Tech stack
build-system, cpp
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.