Skip to main content

Command Palette

Search for a command to run...

First C++ program build via Blade and Clang

Updated
2 min read
N

I’m a backend developer based in Beijing, passionate about crafting efficient and scalable solutions. Amidst my coding endeavors, I’ve embarked on an exciting journey as an active English learner. Exploring the intricacies of language allows me to broaden my horizons and connect with diverse communities worldwide. Join me as I navigate the realms of technology and language, striving for excellence in both.

Q & A

CLANG basic setting

Break point is not accurate


optimize_list = [
  "-O0",
  "-g",
]

Envs

export CXX=clang

compile_flags.txt

# Treat all files as C++ files
-xc++

-std=c++17

BUILD

If use blade, the generated build command with CLANG will invalid, with that it reset the -I option to null.

mock-dep

extra_cppflags = [
    "-Wno-unused-variable"
]

extra_cppflags = [
    "-Wno-unused-variable",
    "-std=c++17",
    "-xc++",
]

optimize_list = [
  "-O0",
  "-g",
]

cc_library(
    name = "myfolly",
    hdrs = [
        "include/myfolly/hello.h",
    ],
    srcs= [
        "src/hello.cpp",
    ],
    incs = [
        "//cpp3rdlib/myfolly/include",
        "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1",  # Path to C++ standard library headers
    ],
    extra_cppflags = extra_cppflags,
    optimize = optimize_list,
    visibility = "PUBLIC",
    export_incs = ["include"],
)
extra_cppflags = [
    "-Wno-unused-variable"
]

extra_cppflags = [
    "-Wno-unused-variable",
    "-std=c++17",
    "-xc++",
]

optimize_list = [
  "-O0",
  "-g",
]

cc_library(
    name = "folly",
    hdrs = [        
        "include/folly/FBString.h",
    ],
    incs = [
        "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1",  # Path to C++ standard library headers
    ],
    deps = [
        "#dl",
        "#pthread",
        "#atomic",
        "//cpp3rdlib/boost:boost",
        "//cpp3rdlib/fmt-11.0.2:fmt",
    ],
    export_incs = ["include"],
    visibility = ["PUBLIC"],
    prebuilt = True,
)

And the dependency file structure could be like this

➜  myfolly pwd
/Volumes/repos/blade/cpp3rdlib/myfolly
➜  myfolly tree
.
├── BUILD
├── include
│   └── myfolly
│       └── hello.h
└── src
    └── hello.cpp

4 directories, 3 files

main.cpp

extra_cppflags = [
    "-Wno-unused-variable"
]

extra_cppflags = [
    "-Wno-unused-variable",
    "-std=c++17",
    "-xc++",
]

optimize_list = [
  "-O0",
  "-g",
]

cc_library(
    name = "myfolly",
    hdrs = [
        "include/myfolly/hello.h",
    ],
    srcs= [
        "src/hello.cpp",
    ],
    incs = [
        "//cpp3rdlib/myfolly/include",
        "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1",  # Path to C++ standard library headers
    ],
    extra_cppflags = extra_cppflags,
    optimize = optimize_list,
    visibility = "PUBLIC",
    export_incs = ["include"],
)

CLang V.S G++

Clang has built-in support for atomic operations, so the need for libatomic might be due to a specific flag or configuration in your build system. Check your build scripts for flags like -latomic or similar, and try removing them or replacing them with Clang-compatible options.
32 views

More from this blog

W

Way to far away

10 posts

I’m a backend developer based in Beijing, passionate about crafting efficient and scalable solutions. Amidst my coding endeavors, I’ve embarked on an exciting journey as an active English learner.