Bazel: Why can GCC suddenly not find stdlib.h anymore?

My WORKSPACE file contains this code snippet:

new_local_repository(
    name = "boost",
    build_file = "//bazel/third_party:boost.BUILD",
    path = "C:/msys64/mingw64/include"
)

bazel/third_party:boost.BUILD looks like that:

cc_library(
    name = "boost",
    includes = ["."],
    visibility = ["//visibility:public"]
)

Building the main target, that depends on boost, works perfectly fine.

Now let’s remove “include” from the path attribute in the WORKSPACE file and add it to the includes attribute in bazel/third_party:boost.BUILD:

WORKSPACE:

new_local_repository(
    name = "boost",
    build_file = "//bazel/third_party:boost.BUILD",
    path = "C:/msys64/mingw64"
)

bazel/third_party:boost.BUILD:

cc_library(
    name = "boost",
    includes = ["include"],
    visibility = ["//visibility:public"]
)

Building the main target now suddenly produces this error:

ERROR: C:/users/vschaerl/projects/testbazel/testbazel/src/BUILD:1:10: Compiling src/main.cpp failed: (Exit 1): g++ failed: error executing CppCompile command (from target //src:main) C:msys64mingw64bing++ -MD -MF bazel-out/x64_windows-fastbuild/bin/src/_objs/main/main.d -frandom-seed=bazel-out/x64_windows-fastbuild/bin/src/_objs/main/main.o -iquote . -iquote ... (remaining 25 arguments skipped)
In file included from C:/msys64/mingw64/include/c++/13.2.0/ext/string_conversions.h:43,
                 from C:/msys64/mingw64/include/c++/13.2.0/bits/basic_string.h:4097,
                 from C:/msys64/mingw64/include/c++/13.2.0/string:54,
                 from C:/msys64/mingw64/include/c++/13.2.0/bits/locale_classes.h:40,
                 from C:/msys64/mingw64/include/c++/13.2.0/bits/ios_base.h:41,
                 from C:/msys64/mingw64/include/c++/13.2.0/streambuf:43,
                 from C:/msys64/mingw64/include/c++/13.2.0/bits/streambuf_iterator.h:35,
                 from C:/msys64/mingw64/include/c++/13.2.0/iterator:66,
                 from external/boost/include/boost/array.hpp:44,
                 from src/main.cpp:1:
C:/msys64/mingw64/include/c++/13.2.0/cstdlib:79:15: fatal error: stdlib.h: No such file or directory
   79 | #include_next <stdlib.h>
      |               ^~~~~~~~~~
compilation terminated.
Target //src:main failed to build

Why? Shouln’t it behave just the same? I only moved “include” from path to includes

By the way, I’m on Windows and defined a custom MinGW toolchain for Bazel according to this tutorial: https://github.com/EhabHelaly/bazel_mingw_toolchain

And there are three stdlib.h files in C:msys64mingw64include:

  • in C:msys64mingw64include
  • in C:msys64mingw64includec++13.2.0
  • in C:msys64mingw64includec++13.2.0tr1

Thanks a lot.

EDIT/ADDITIONAL INFORMATION:

This is the compiler command line generated by Bazel before moving “include” from path to includes, when everything works fine (I separated the compiler options by lines for better readability):

C:msys64mingw64bing++
-MD
-MF bazel-out/x64_windows-fastbuild/bin/src/_objs/main/main.d
-frandom-seed=bazel-out/x64_windows-fastbuild/bin/src/_objs/main/main.o
-iquote .
-iquote bazel-out/x64_windows-fastbuild/bin
-iquote external/boost
-iquote bazel-out/x64_windows-fastbuild/bin/external/boost
-iquote external/bazel_tools
-iquote bazel-out/x64_windows-fastbuild/bin/external/bazel_tools
-isystem external/boost
-isystem bazel-out/x64_windows-fastbuild/bin/external/boost
-c src/main.cpp
-o bazel-out/x64_windows-fastbuild/bin/src/_objs/main/main.o

This is the compiler command line after moving “include” from path to includes, which produces said error:

C:msys64mingw64bing++
-MD 
-MF bazel-out/x64_windows-fastbuild/bin/src/_objs/main/main.d
-frandom-seed=bazel-out/x64_windows-fastbuild/bin/src/_objs/main/main.o
-iquote .
-iquote bazel-out/x64_windows-fastbuild/bin
-iquote external/boost
-iquote bazel-out/x64_windows-fastbuild/bin/external/boost
-iquote external/bazel_tools
-iquote bazel-out/x64_windows-fastbuild/bin/external/bazel_tools
-isystem external/boost/include
-isystem bazel-out/x64_windows-fastbuild/bin/external/boost/include
-c src/main.cpp
-o bazel-out/x64_windows-fastbuild/bin/src/_objs/main/main.o

I think the problem lies in -iquote external/boost not changing. Before, external/boost points to C:msys64mingw64include, which is the correct path, but after, it points to C:msys64mingw64, which is not correct. Why does Bazel not change the path in the -iquote compiler option?

EDIT 2:

echo | gcc -Wp,-v -x c++ - -fsyntax-only, which according to /a/19839946/18226035 shows the default GCC include directories, prints this:

ignoring nonexistent directory "C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/include"
ignoring duplicate directory "C:/msys64/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../include/c++/13.2.0"
ignoring duplicate directory "C:/msys64/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../include/c++/13.2.0/x86_64-w64-mingw32"
ignoring duplicate directory "C:/msys64/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../include/c++/13.2.0/backward"
ignoring duplicate directory "C:/msys64/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/13.2.0/include"
ignoring nonexistent directory "D:/a/msys64/mingw64/include"
ignoring nonexistent directory "/mingw64/include"
ignoring duplicate directory "C:/msys64/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/13.2.0/include-fixed"
ignoring nonexistent directory "C:/msys64/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/include"
ignoring nonexistent directory "D:/a/msys64/mingw64/include"
#include "..." search starts here:
#include <...> search starts here:
 C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../include/c++/13.2.0
 C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../include/c++/13.2.0/x86_64-w64-mingw32
 C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../include/c++/13.2.0/backward
 C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/include
 C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../include
 C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/include-fixed
End of search list.

8

I notice the compiler command line generated by Bazel after moving include dir to includes is that the -isystem path has include dir appended at the end of the original -isystem path.

Before change

-isystem external/boost
-isystem bazel-out/x64_windows-fastbuild/bin/external/boost

After change

-isystem external/boost/include
-isystem bazel-out/x64_windows-fastbuild/bin/external/boost/include

From the documentation, adding directories to the includes field would generate -isystem <path_to_package>/<include_entry> flags. This is consistent with the addition of include dir in the includes. However, it doesn’t explain that why <path_to_package> remains unchanged. My guess is that <path_to_package> is configured elsewhere. To generate similar g++ command that worked, I don’t think you need to add include in includes while also keeping path = "C:/msys64/mingw64" updated because it doesn’t affect the generated g++ command

WORKSPACE:

new_local_repository(
    name = "boost",
    build_file = "//bazel/third_party:boost.BUILD",
    path = "C:/msys64/mingw64"
)

bazel/third_party:boost.BUILD:

cc_library(
    name = "boost",
    includes = ["."],
    visibility = ["//visibility:public"]
)

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật