简体   繁体   中英

Buildroot: CMake: arch64-none-linux-gnu/include/c++/9.2.1/cstdlib:75:15: fatal error: stdlib.h: No such file or directory while building grpc package

I'm upgrading a Buildroot build system from gcc-8 on Ubuntu 18.04 to gcc-11 on Ubuntu 22.04, and am really struggling with it.

While building grpc 1.32.0, I am seeing a lot of this:

host/opt/ext-toolchain/aarch64-none-linux-gnu/include/c++/9.2.1/cstdlib:75:15: fatal error: stdlib.h: No such file or directory
   75 | #include_next <stdlib.h>
      |               ^~~~~~~~~~
compilation terminated.
make[5]: *** [CMakeFiles/grpc_plugin_support.dir/build.make:104: CMakeFiles/grpc_plugin_support.dir/src/compiler/node_generator.cc.o] Error 1

stdlib.h is present right there at host/opt/ext-toolchain/aarch64-none-linux-gnu/include/c++/9.2.1/stdlib.h .

I tried upgrading grpc to the latest from buildroot ( currently 1.51.1, here ) and am still seeing the error.

The latest grpc is here:https://github.com/buildroot/buildroot/tree/master/package/grpc

To update mine to that latest, I did this:

# fetch latest from upstream buildroot
cd path/to/buildroot
git remote add upstream https://github.com/buildroot/buildroot.git
git fetch upstream master

# grab those changes for the grpc package only
rm -r package/grpc
git checkout upstream/master -- package/grpc
git add -A
git status
git commit -m "Update grpc library"

This seems to get the build to pass for that package:

after updating to the latest grpc package as explained in my question, add this define to your CMake build options: CMAKE_NO_SYSTEM_FROM_IMPORTED=1 .

To do that, I opened my buildroot/package/grpc/grpc.mk makefile, and changed this:

GRPC_CONF_OPTS += \
    -DCMAKE_C_FLAGS="$(GRPC_CFLAGS)" \
    -DCMAKE_CXX_FLAGS="$(GRPC_CXXFLAGS)"

to this:

GRPC_CONF_OPTS += \
    -DCMAKE_C_FLAGS="$(GRPC_CFLAGS)" \
    -DCMAKE_CXX_FLAGS="$(GRPC_CXXFLAGS)" \
    -DCMAKE_NO_SYSTEM_FROM_IMPORTED=1
# For just above, see: https://github.com/sony/nmos-cpp/issues/150#issuecomment-817259703

Here is the final version of my buildroot/package/grpc/grpc.mk file now:

################################################################################
#
# grpc
#
################################################################################

GRPC_VERSION = 1.51.1
GRPC_SITE = $(call github,grpc,grpc,v$(GRPC_VERSION))
GRPC_LICENSE = Apache-2.0, BSD-3-Clause (third_party code), MPL-2.0 (etc/roots.pem)
GRPC_LICENSE_FILES = LICENSE
GRPC_CPE_ID_VENDOR = grpc

GRPC_INSTALL_STAGING = YES

# Need to use host grpc_cpp_plugin during cross compilation.
GRPC_DEPENDENCIES = c-ares host-grpc libabseil-cpp openssl protobuf re2 zlib
HOST_GRPC_DEPENDENCIES = host-protobuf

# gRPC_CARES_PROVIDER=package won't work because it requires c-ares to have
# installed a cmake config file, but buildroot uses c-ares' autotools build,
# which doesn't do this.  These CARES settings trick the gRPC cmake code into
# not looking for c-ares at all and yet still linking with the library.
GRPC_CONF_OPTS = \
    -DCMAKE_EXE_LINKER_FLAGS="$(GRPC_EXE_LINKER_FLAGS)" \
    -DgRPC_ABSL_PROVIDER=package \
    -D_gRPC_CARES_LIBRARIES=cares \
    -DgRPC_CARES_PROVIDER=none \
    -DgRPC_PROTOBUF_PROVIDER=package \
    -DgRPC_RE2_PROVIDER=package \
    -DgRPC_SSL_PROVIDER=package \
    -DgRPC_ZLIB_PROVIDER=package \
    -DgRPC_BUILD_GRPC_CPP_PLUGIN=OFF \
    -DgRPC_BUILD_GRPC_CSHARP_PLUGIN=OFF \
    -DgRPC_BUILD_GRPC_NODE_PLUGIN=OFF \
    -DgRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN=OFF \
    -DgRPC_BUILD_GRPC_PHP_PLUGIN=OFF \
    -DgRPC_BUILD_GRPC_PYTHON_PLUGIN=OFF \
    -DgRPC_BUILD_GRPC_RUBY_PLUGIN=OFF

ifeq ($(BR2_PACKAGE_LIBEXECINFO),y)
GRPC_DEPENDENCIES += libexecinfo
GRPC_EXE_LINKER_FLAGS += -lexecinfo
endif

# grpc can use __atomic builtins, so we need to link with
# libatomic when available
ifeq ($(BR2_TOOLCHAIN_HAS_LIBATOMIC),y)
GRPC_EXE_LINKER_FLAGS += -latomic
endif

GRPC_CFLAGS = $(TARGET_CFLAGS)
GRPC_CXXFLAGS = $(TARGET_CXXFLAGS)

# Set GPR_DISABLE_WRAPPED_MEMCPY otherwise build will fail on x86_64 with uclibc
# because grpc tries to link with memcpy@GLIBC_2.2.5
ifeq ($(BR2_x86_64):$(BR2_TOOLCHAIN_USES_GLIBC),y:)
GRPC_CFLAGS += -DGPR_DISABLE_WRAPPED_MEMCPY
GRPC_CXXFLAGS += -DGPR_DISABLE_WRAPPED_MEMCPY
endif

ifeq ($(BR2_TOOLCHAIN_HAS_GCC_BUG_85180),y)
GRPC_CFLAGS += -O0
GRPC_CXXFLAGS += -O0
endif

GRPC_CONF_OPTS += \
    -DCMAKE_C_FLAGS="$(GRPC_CFLAGS)" \
    -DCMAKE_CXX_FLAGS="$(GRPC_CXXFLAGS)" \
    -DCMAKE_NO_SYSTEM_FROM_IMPORTED=1
# For just above, see: https://github.com/sony/nmos-cpp/issues/150#issuecomment-817259703

# For host-grpc, we only need the 'grpc_cpp_plugin' binary, which is needed for
# target grpc compilation. To avoid unnecessary build steps and host
# dependencies, supply enough options to pass the configure checks without
# requiring other host packages, unless those needed by grpc_cpp_plugin.
HOST_GRPC_CONF_OPTS = \
    -DgRPC_PROTOBUF_PROVIDER=package \
    -DgRPC_ABSL_PROVIDER=none \
    -DgRPC_CARES_PROVIDER=none \
    -DgRPC_RE2_PROVIDER=none \
    -DgRPC_SSL_PROVIDER=none \
    -DgRPC_ZLIB_PROVIDER=none \
    -DgRPC_BUILD_CODEGEN=OFF \
    -DgRPC_BUILD_CSHARP_EXT=OFF \
    -DgRPC_BUILD_PLUGIN_SUPPORT_ONLY=ON \
    -DgRPC_BUILD_GRPC_CSHARP_PLUGIN=OFF \
    -DgRPC_BUILD_GRPC_NODE_PLUGIN=OFF \
    -DgRPC_BUILD_GRPC_OBJECTIVE_C_PLUGIN=OFF \
    -DgRPC_BUILD_GRPC_PHP_PLUGIN=OFF \
    -DgRPC_BUILD_GRPC_PYTHON_PLUGIN=OFF \
    -DgRPC_BUILD_GRPC_RUBY_PLUGIN=OFF

$(eval $(cmake-package))
$(eval $(host-cmake-package))

I don't really understand what I'm doing, nor why this works. I first saw it here: https://github.com/sony/nmos-cpp/issues/150#issuecomment-817259703

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM