# First C++ program build via Blade and Clang

# Q & A

CLANG basic setting

## Break point is not accurate

```bash

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

## Envs

```bash
export CXX=clang
```

## compile\_flags.txt

```plaintext
# 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

```bash
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"],
)
```

```bash
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

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

4 directories, 3 files
```

main.cpp

```plaintext
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++

```bash
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.
```
