Skip to content

Commit 7a5fc71

Browse files
committed
Fix to build with C++ environment
C++ requires additional runtime to be linked by rust linker. Reference: rust-lang/rust#36710 (comment)
1 parent 8d34cdb commit 7a5fc71

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

.cargo/config

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
[target.x86_64-unknown-linux-musl]
2-
linker = "/opt/cross/bin/x86_64-linux-musl-gcc"
3-
rustflags = ["-C", "link-args=-static"]
2+
linker = "./linker"

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ rust:
1111

1212
.PHONY: rust-musl
1313
rust-musl:
14-
CXX=/opt/cross/bin/x86_64-linux-musl-g++ cargo run --target x86_64-unknown-linux-musl
14+
CROSS_COMPILE=/opt/cross/bin/x86_64-linux-musl- cargo run --target x86_64-unknown-linux-musl

linker

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
args=()
4+
5+
for arg in "$@"; do
6+
if [[ $arg = *"Bdynamic"* ]]; then
7+
args+=() # we do not want this arg
8+
elif [[ $arg = *"crti.o"* ]]; then
9+
args+=("$arg" "/home/blmarket/proj/musl-cross-make/output/lib/gcc/x86_64-linux-musl/9.2.0/crtbeginS.o" "-Bstatic")
10+
elif [[ $arg = *"crtn.o"* ]]; then
11+
args+=("-lgcc" "-lgcc_eh" "-lc" "/home/blmarket/proj/musl-cross-make/output/lib/gcc/x86_64-linux-musl/9.2.0/crtendS.o" "$arg")
12+
else
13+
args+=("$arg")
14+
fi
15+
done
16+
17+
echo "RUNNING WITH ARGS: ${args[@]}"
18+
/opt/cross/bin/x86_64-linux-musl-g++ "${args[@]}"

0 commit comments

Comments
 (0)