Skip to content

Commit

Permalink
Simply cc program to not require libcxx
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinh Tran committed Feb 6, 2024
1 parent 3e5abde commit ee9c67c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
18 changes: 11 additions & 7 deletions cc-toolchain/basic/gcc/toolchain/cc_toolchain.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ cc_toolchain_config(
name = "cc_toolchain_config",
abi_libc_version = "unknown",
abi_version = "unknown",
# TODO Remove absolute path
builtin_sysroot = "external/gcc_toolchain/x86_64-buildroot-linux-gnu/sysroot",
compile_flags = [
# "-no-canonical-prefixes",
"-v",
"-no-canonical-prefixes",
"-fno-canonical-system-headers",
"-isystem",
"external/gcc_toolchain/x86_64-buildroot-linux-gnu/include/c++/12.3.0",
Expand All @@ -32,9 +30,11 @@ cc_toolchain_config(
],
host_system_name = "local",
link_flags = [
"-v",
# "-fuse-ld=lld",
"-print-search-dirs",
# "-Wl,--sysroot=/usr/local/google/home/vinhdaitran/github/daivinhtran/examples/cc-toolchain/bazel-cc-toolchain/external/gcc_toolchain/x86_64-buildroot-linux-gnu/sysroot",
# FIX ME: Needed to link to libc.so.6 from toolchain's sysroot instead of /lib/x86_64-linux-gnu/libc.so.6
# Error: cannot find /lib64/libc.so.6: cannot find /usr/lib64/libc_nonshared.a:
# Symlinks in Bazel sandbox messes up the sysroot so libc.so.6 and libc_nonshared.a can't be found
# Running the link action outsize of Bazel works.
"-Bexternal/gcc_toolchain/x86_64-buildroot-linux-gnu/sysroot/bin",
"-Bexternal/gcc_toolchain/x86_64-buildroot-linux-gnu/sysroot/usr/lib64",
"-Bexternal/gcc_toolchain/x86_64-buildroot-linux-gnu/sysroot/lib64",
Expand Down Expand Up @@ -94,9 +94,13 @@ filegroup(
srcs = glob(
include = [
"lib64/**",
# FIX ME: Even though link action sets --sysroot=external/gcc_toolchain/x86_64-buildroot-linux-gnu/sysroot
# libc.so.6 is not found.
# See https://stackoverflow.com/questions/52386530/linker-fails-in-sandbox-when-running-through-bazel-but-works-when-sandboxed-comm
# Symlinks in Bazel sandbox messes up the sysroot so libc.so.6 and libc_nonshared.a can't be found
# Running the link action outsize of Bazel works.
"x86_64-buildroot-linux-gnu/sysroot/lib64/libc.so.6",
"x86_64-buildroot-linux-gnu/sysroot/usr/lib64/**",
# "x86_64-buildroot-linux-gnu/sysroot/usr/lib64/crti.o",
"lib64/gcc/x86_64-buildroot-linux-gnu/12.3.0/**",
],
exclude = [
Expand Down
16 changes: 5 additions & 11 deletions cc-toolchain/main/hello-world.cc
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#include <iostream>

std::string get_greet(const std::string& who) {
return "Hello " + who;
}


int main(int argc, char** argv) {
// std::string who = "world";
// std::cout << get_greet(who) << std::endl;
return 0;
#include <stdio.h>
int main() {
// printf() displays the string inside quotation
printf("Hello, World!");
return 0;
}

0 comments on commit ee9c67c

Please sign in to comment.