Building a pure C program produces a binary with unneded dependencies
- Dominant language
- C++
- Stars
- 251
- Forks
- 63
- PR merge metrics
- No merged PRs in 30d
Description
a.c:
```
int main() { return 0; }
```
jamroot.jam:
```
exe a : a.c ;
```
Build:
```
$ b2 toolset=gcc -d+2
common.mkdir bin
mkdir -p "bin"
common.mkdir bin/gcc-8
mkdir -p "bin/gcc-8"
common.mkdir bin/gcc-8/debug
mkdir -p "bin/gcc-8/debug"
gcc.compile.c bin/gcc-8/debug/a.o
"g++" -x c -fPIC -O0 -fno-inline -Wall -g -c -o "bin/gcc-8/debug/a.o" "a.c"
gcc.link bin/gcc-8/debug/a
"g++" -o "bin/gcc-8/debug/a" -Wl,--start-group "bin/gcc-8/debug/a.o" -Wl,-Bstatic -Wl,-Bdynamic -Wl,--end-group -fPIC -g
```
Resulting binary dependencies:
```
$ ldd bin/gcc-8/debug/a
linux-vdso.so.1 (0x00007ffd25cf3000)
libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f7373bab000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7373a28000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7373a0e000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f737384d000)
/lib64/ld-linux-x86-64.so.2 (0x00007f7373d5e000)
```
If I build with gcc I get much less dependencies:
```
$ gcc a.c -o a
$ ldd ./a
linux-vdso.so.1 (0x00007ffce34e5000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f1774547000)
/lib64/ld-linux-x86-64.so.2 (0x00007f1774737000)
```
```
$ b2 --version
B2 4.2-git
$ g++ --version
g++ (Debian 8.3.0-6) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ cat /etc/debian_version
10.7
$ arch
x86_64
```
Contributor guide
Research direction
Start with the a.c and jamroot.jam reproducer, then run b2 toolset=gcc -d+2 and compare its link command with gcc a.c -o a. Trace why the pure C target invokes g++ and verify completion by rebuilding it and confirming that the resulting binary no longer has the unwanted C++ runtime dependencies.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, cpp
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100