'How to specify -std=c++11 option in bazel BUILD file?

How to add this option into a target description section?

Thanks.



Solution 1:[1]

Add bazel build --cxxopt='-std=c++11' to .bazelrc file.

Solution 2:[2]

export BAZEL_CXXOPTS=-std=c++11

see source

Solution 3:[3]

Besides setting it globally in .bazelrc or using BAZEL_CXXOPTS , you can also set them individually for each target in their cc_binary or cc_test rules:

cc_binary(
    name = "target1",
    srcs = ["target1.cc"],
    copts = ["--std=c++17"],
)

cc_binary(
    name = "target2",
    srcs = ["target2.cc"],
    copts = ["--std=c++14"],
)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 P.W
Solution 2 CodeFarmer
Solution 3 Ari