lzhiyong / android-sdk-tools

building android-sdk tools for Android
Apache License 2.0
377 stars 65 forks source link

common.cc:41:10: fatal error: config.h: No such file or directory ? #36

Open redfirebrooks opened 9 months ago

redfirebrooks commented 9 months ago

Hello, I have followed the different steps but have a error with ninja

pi@raspberry4:~/android-sdk-tools/src/protobuf/build $ ninja -j$(nproc --all)
[1/179] Building CXX object CMakeFiles/libprotobuf.dir/src/google/protobuf/stubs/common.cc.o
FAILED: CMakeFiles/libprotobuf.dir/src/google/protobuf/stubs/common.cc.o
/usr/bin/c++ -DGOOGLE_PROTOBUF_CMAKE_BUILD -DHAVE_ZLIB -I. -I../src -std=c++11 -MD -MT CMakeFiles/libprotobuf.dir/src/google/protobuf/stubs/common.cc.o -MF CMakeFiles/libprotobuf.dir/src/google/protobuf/stubs/common.cc.o.d -o CMakeFiles/libprotobuf.dir/src/google/protobuf/stubs/common.cc.o -c ../src/google/protobuf/stubs/common.cc
../src/google/protobuf/stubs/common.cc:41:10: fatal error: config.h: No such file or directory
   41 | #include "config.h"
      |          ^~~~~~~~~~
compilation terminated.
[4/179] Building CXX object CMakeFiles/libprotobuf.dir/src/google/protobuf/stubs/stringprintf.cc.o
ninja: build stopped: subcommand failed.
gounthar commented 6 months ago

I have the same problem on an aarch64 server I use for all my builds (Linux instance-20240118-1509 6.5.0-1021-oracle #21~22.04.1-Ubuntu SMP Fri Apr 5 20:30:17 UTC 2024 aarch64 aarch64 aarch64 GNU/Linux):

python3 get_source.py
/usr/bin/git

/usr/bin/go

Cloning into 'src/core'...
remote: Finding sources: 100% (2096/2096)
remote: Total 2096 (delta 192), reused 1308 (delta 192)
Receiving objects: 100% (2096/2096), 2.44 MiB | 10.33 MiB/s, done.
Resolving deltas: 100% (192/192), done.
Cloning into 'src/extras'...
remote: Finding sources: 100% (1470/1470)
remote: Total 1470 (delta 138), reused 1064 (delta 138)
Receiving objects: 100% (1470/1470), 254.86 MiB | 37.32 MiB/s, done.
Resolving deltas: 100% (138/138), done.
Updating files: 100% (1189/1189), done.
Cloning into 'src/selinux'...
remote: Finding sources: 100% (1811/1811)
remote: Total 1811 (delta 340), reused 851 (delta 340)
Receiving objects: 100% (1811/1811), 5.58 MiB | 8.80 MiB/s, done.
Resolving deltas: 100% (340/340), done.
Cloning into 'src/f2fs-tools'...
remote: Finding sources: 100% (96/96)
remote: Total 96 (delta 2), reused 58 (delta 2)
Receiving objects: 100% (96/96), 294.54 KiB | 8.42 MiB/s, done.
Resolving deltas: 100% (2/2), done.
Cloning into 'src/e2fsprogs'...
remote: Finding sources: 100% (2606/2606)
remote: Total 2606 (delta 456), reused 1854 (delta 456)
Receiving objects: 100% (2606/2606), 9.39 MiB | 10.43 MiB/s, done.
Resolving deltas: 100% (456/456), done.
Cloning into 'src/boringssl'...
remote: Finding sources: 100% (1870/1870)
remote: Total 1870 (delta 276), reused 1461 (delta 276)
Receiving objects: 100% (1870/1870), 41.96 MiB | 22.28 MiB/s, done.
Resolving deltas: 100% (276/276), done.
Cloning into 'src/mkbootimg'...
remote: Finding sources: 100% (31/31)
remote: Total 31 (delta 1), reused 21 (delta 1)
Receiving objects: 100% (31/31), 52.72 KiB | 7.53 MiB/s, done.
Resolving deltas: 100% (1/1), done.
Cloning into 'src/avb'...
remote: Finding sources: 100% (199/199)
remote: Total 199 (delta 15), reused 143 (delta 15)
Receiving objects: 100% (199/199), 926.91 KiB | 22.07 MiB/s, done.
Resolving deltas: 100% (15/15), done.
Cloning into 'src/libbase'...
remote: Finding sources: 100% (102/102)
remote: Total 102 (delta 10), reused 68 (delta 10)
Receiving objects: 100% (102/102), 145.04 KiB | 6.91 MiB/s, done.
Resolving deltas: 100% (10/10), done.
Cloning into 'src/base'...
remote: Finding sources: 100% (63295/63295)
remote: Total 63295 (delta 12825), reused 41506 (delta 12825)
Receiving objects: 100% (63295/63295), 942.63 MiB | 20.30 MiB/s, done.
Resolving deltas: 100% (12825/12825), done.
Updating files: 100% (50016/50016), done.
Cloning into 'src/native'...
remote: Finding sources: 100% (4268/4268)
remote: Total 4268 (delta 464), reused 2143 (delta 464)
Receiving objects: 100% (4268/4268), 12.18 MiB | 8.75 MiB/s, done.
Resolving deltas: 100% (464/464), done.
Cloning into 'src/adb'...
remote: Finding sources: 100% (344/344)
remote: Total 344 (delta 32), reused 218 (delta 32)
Receiving objects: 100% (344/344), 5.24 MiB | 14.78 MiB/s, done.
Resolving deltas: 100% (32/32), done.
Cloning into 'src/logging'...
remote: Finding sources: 100% (222/222)
remote: Total 222 (delta 22), reused 131 (delta 22)
Receiving objects: 100% (222/222), 882.70 KiB | 13.79 MiB/s, done.
Resolving deltas: 100% (22/22), done.
Cloning into 'src/incremental_delivery'...
remote: Finding sources: 100% (59/59)
remote: Total 59 (delta 2), reused 40 (delta 2)
Receiving objects: 100% (59/59), 88.78 KiB | 12.68 MiB/s, done.
Resolving deltas: 100% (2/2), done.
Cloning into 'src/fmtlib'...
remote: Finding sources: 100% (245/245)
remote: Total 245 (delta 6), reused 141 (delta 6)
Receiving objects: 100% (245/245), 875.63 KiB | 5.09 MiB/s, done.
Resolving deltas: 100% (6/6), done.
Cloning into 'src/pcre'...
remote: Finding sources: 100% (499/499)
remote: Total 499 (delta 81), reused 247 (delta 81)
Receiving objects: 100% (499/499), 3.24 MiB | 6.94 MiB/s, done.
Resolving deltas: 100% (81/81), done.
Cloning into 'src/libpng'...
remote: Finding sources: 100% (531/531)
remote: Total 531 (delta 155), reused 316 (delta 155)
Receiving objects: 100% (531/531), 1.48 MiB | 5.48 MiB/s, done.
Resolving deltas: 100% (155/155), done.
Cloning into 'src/expat'...
remote: Finding sources: 100% (184/184)
remote: Total 184 (delta 16), reused 56 (delta 16)
Receiving objects: 100% (184/184), 7.99 MiB | 7.44 MiB/s, done.
Resolving deltas: 100% (16/16), done.
Cloning into 'src/protobuf'...
remote: Finding sources: 100% (2649/2649)
remote: Total 2649 (delta 412), reused 1016 (delta 412)
Receiving objects: 100% (2649/2649), 6.24 MiB | 4.34 MiB/s, done.
Resolving deltas: 100% (412/412), done.
Cloning into 'src/aidl'...
remote: Finding sources: 100% (1709/1709)
remote: Total 1709 (delta 504), reused 1205 (delta 504)
Receiving objects: 100% (1709/1709), 1009.09 KiB | 8.27 MiB/s, done.
Resolving deltas: 100% (504/504), done.
Cloning into 'src/unwinding'...
remote: Finding sources: 100% (601/601)
remote: Total 601 (delta 101), reused 500 (delta 101)
Receiving objects: 100% (601/601), 47.54 MiB | 60.33 MiB/s, done.
Resolving deltas: 100% (101/101), done.
Cloning into 'src/zopfli'...
remote: Finding sources: 100% (59/59)
remote: Total 59 (delta 2), reused 30 (delta 2)
Receiving objects: 100% (59/59), 213.43 KiB | 9.70 MiB/s, done.
Resolving deltas: 100% (2/2), done.
Cloning into 'src/jsoncpp'...
remote: Finding sources: 100% (271/271)
remote: Total 271 (delta 11), reused 260 (delta 11)
Receiving objects: 100% (271/271), 189.80 KiB | 15.82 MiB/s, done.
Resolving deltas: 100% (11/11), done.
Cloning into 'src/art'...
remote: Finding sources: 100% (10611/10611)
remote: Total 10611 (delta 2511), reused 7752 (delta 2511)
Receiving objects: 100% (10611/10611), 16.20 MiB | 10.50 MiB/s, done.
Resolving deltas: 100% (2511/2511), done.
Cloning into 'src/dalvik'...
remote: Finding sources: 100% (1992/1992)
remote: Total 1992 (delta 575), reused 1311 (delta 575)
Receiving objects: 100% (1992/1992), 3.31 MiB | 13.88 MiB/s, done.
Resolving deltas: 100% (575/575), done.
Cloning into 'src/sqlite'...
remote: Finding sources: 100% (55/55)
remote: Total 55 (delta 7), reused 42 (delta 7)
Receiving objects: 100% (55/55), 5.13 MiB | 5.68 MiB/s, done.
Resolving deltas: 100% (7/7), done.
Cloning into 'src/lz4'...
remote: Finding sources: 100% (243/243)
remote: Total 243 (delta 27), reused 109 (delta 27)
Receiving objects: 100% (243/243), 386.36 KiB | 6.04 MiB/s, done.
Resolving deltas: 100% (27/27), done.
Cloning into 'src/zstd'...
remote: Finding sources: 100% (744/744)
remote: Total 744 (delta 54), reused 311 (delta 54)
Receiving objects: 100% (744/744), 2.46 MiB | 7.17 MiB/s, done.
Resolving deltas: 100% (54/54), done.
Cloning into 'src/libusb'...
remote: Finding sources: 100% (187/187)
remote: Total 187 (delta 17), reused 82 (delta 17)
Receiving objects: 100% (187/187), 456.40 KiB | 4.23 MiB/s, done.
Resolving deltas: 100% (17/17), done.
Cloning into 'src/brotli'...
remote: Finding sources: 100% (380/380)
remote: Total 380 (delta 15), reused 187 (delta 15)
Receiving objects: 100% (380/380), 22.50 MiB | 40.20 MiB/s, done.
Resolving deltas: 100% (15/15), done.
Cloning into 'src/mdnsresponder'...
remote: Finding sources: 100% (271/271)
remote: Total 271 (delta 109), reused 254 (delta 109)
Receiving objects: 100% (271/271), 1.05 MiB | 15.18 MiB/s, done.
Resolving deltas: 100% (109/109), done.
Cloning into 'src/abseil-cpp'...
remote: Finding sources: 100% (1447/1447)
remote: Total 1447 (delta 244), reused 496 (delta 244)
Receiving objects: 100% (1447/1447), 2.58 MiB | 6.36 MiB/s, done.
Resolving deltas: 100% (244/244), done.
Cloning into 'src/openscreen'...
remote: Finding sources: 100% (2473/2473)
remote: Total 2473 (delta 476), reused 1915 (delta 476)
Receiving objects: 100% (2473/2473), 15.33 MiB | 29.24 MiB/s, done.
Resolving deltas: 100% (476/476), done.
Cloning into 'src/googletest'...
remote: Finding sources: 100% (287/287)
remote: Total 287 (delta 12), reused 68 (delta 12)
Receiving objects: 100% (287/287), 1.00 MiB | 5.89 MiB/s, done.
Resolving deltas: 100% (12/12), done.
Cloning into 'src/libziparchive'...
remote: Finding sources: 100% (54/54)
remote: Total 54 (delta 1), reused 40 (delta 1)
Receiving objects: 100% (54/54), 1.13 MiB | 44.40 MiB/s, done.
Resolving deltas: 100% (1/1), done.
Cloning into 'src/build'...
remote: Finding sources: 100% (1576/1576)
remote: Total 1576 (delta 241), reused 992 (delta 241)
Receiving objects: 100% (1576/1576), 6.97 MiB | 25.22 MiB/s, done.
Resolving deltas: 100% (241/241), done.
Cloning into 'src/development'...
remote: Finding sources: 100% (11856/11856)
remote: Total 11856 (delta 2645), reused 8703 (delta 2645)
Receiving objects: 100% (11856/11856), 210.52 MiB | 26.07 MiB/s, done.
Resolving deltas: 100% (2645/2645), done.
Updating files: 100% (9901/9901), done.
Cloning into 'src/soong'...
remote: Finding sources: 100% (1272/1272)
remote: Total 1272 (delta 74), reused 662 (delta 74)
Receiving objects: 100% (1272/1272), 2.98 MiB | 9.63 MiB/s, done.
Resolving deltas: 100% (74/74), done.
download success!!
ubuntu@instance-20240118-1509 ~/android-sdk-tools (master)$ cd src/protobuf && mkdir build && cd build
ubuntu@instance-20240118-1509 ~/android-sdk-tools/src/protobuf/build (master)$ cmake -GNinja -Dprotobuf_BUILD_TESTS=OFF ..
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
--
-- 3.21.12.0
-- Performing Test protobuf_HAVE_LD_VERSION_SCRIPT
-- Performing Test protobuf_HAVE_LD_VERSION_SCRIPT - Success
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Could NOT find ZLIB (missing: ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
-- Performing Test protobuf_HAVE_BUILTIN_ATOMICS
-- Performing Test protobuf_HAVE_BUILTIN_ATOMICS - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ubuntu/android-sdk-tools/src/protobuf/build
ubuntu@instance-20240118-1509 ~/android-sdk-tools/src/protobuf/build (master)$ ninja -j$(nproc --all)
[11/205] Building CXX object CMakeFiles/libprotobuf-lite.dir/src/google/protobuf/generated_message_tctable_lite.cc.o
In file included from /home/ubuntu/android-sdk-tools/src/protobuf/src/google/protobuf/generated_message_tctable_lite.cc:36:
/home/ubuntu/android-sdk-tools/src/protobuf/src/google/protobuf/generated_message_tctable_impl.h: In function ‘void google::protobuf::internal::AlignFail(uintptr_t) [with long unsigned int align = 4]’:
/home/ubuntu/android-sdk-tools/src/protobuf/src/google/protobuf/generated_message_tctable_impl.h:256:1: warning: ‘noreturn’ function does return
  256 | }
      | ^
/home/ubuntu/android-sdk-tools/src/protobuf/src/google/protobuf/generated_message_tctable_impl.h: In function ‘void google::protobuf::internal::AlignFail(uintptr_t) [with long unsigned int align = 8]’:
/home/ubuntu/android-sdk-tools/src/protobuf/src/google/protobuf/generated_message_tctable_impl.h:256:1: warning: ‘noreturn’ function does return
[20/205] Building CXX object CMakeFiles/libprotobuf-lite.dir/src/google/protobuf/stubs/common.cc.o
FAILED: CMakeFiles/libprotobuf-lite.dir/src/google/protobuf/stubs/common.cc.o
/usr/bin/c++ -DGOOGLE_PROTOBUF_CMAKE_BUILD -I/home/ubuntu/android-sdk-tools/src/protobuf/build -I/home/ubuntu/android-sdk-tools/src/protobuf/src -std=c++11 -MD -MT CMakeFiles/libprotobuf-lite.dir/src/google/protobuf/stubs/common.cc.o -MF CMakeFiles/libprotobuf-lite.dir/src/google/protobuf/stubs/common.cc.o.d -o CMakeFiles/libprotobuf-lite.dir/src/google/protobuf/stubs/common.cc.o -c /home/ubuntu/android-sdk-tools/src/protobuf/src/google/protobuf/stubs/common.cc
/home/ubuntu/android-sdk-tools/src/protobuf/src/google/protobuf/stubs/common.cc:41:10: fatal error: config.h: No such file or directory
   41 | #include "config.h"
      |          ^~~~~~~~~~
compilation terminated.
[23/205] Building CXX object CMakeFiles/libprotobuf-lite.dir/src/google/protobuf/repeated_field.cc.o
ninja: build stopped: subcommand failed.

What could I install to get rid of this error? Just in case my system would lack libraries, I installed autoconf automake autotools-dev file libltdl-dev libtool m4 zlib1g zlib1g-dev (some of them were in the protobuf documentation), but that did not solve the problem. I built protobuf from source on my machine after installing bazel, and it worked too.

ubuntu@instance-20240118-1509 ~/protobuf (main)$ bazel build :protoc :protobuf
INFO: Analyzed 2 targets (0 packages loaded, 0 targets configured).
INFO: Found 2 targets...
Target //:protoc up-to-date:
  bazel-bin/protoc
[...]
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action

I tried very naively to build protobuf with the same method in this repo source tree:

ubuntu@instance-20240118-1509 ~/android-sdk-tools/src/protobuf (master)$ bazel build :protoc :protobuf
Starting local Bazel server and connecting to it...
WARNING: --enable_bzlmod is set, but no MODULE.bazel file was found at the workspace root. Bazel will create an empty MODULE.bazel file. Please consider migrating your external dependencies from WORKSPACE to MODULE.bazel. For more details, please refer to https://github.com/bazelbuild/bazel/issues/18958.
DEBUG: /home/ubuntu/.cache/bazel/_bazel_ubuntu/f7c6c2b6616329c5799c427cd54ca291/external/rules_jvm_external/coursier.bzl:445:22: The inputs to maven_install.json have changed, but the lock file has not been regenerated. Consider running 'bazel run @unpinned_maven//:pin'
ERROR: Traceback (most recent call last):
        File "/home/ubuntu/android-sdk-tools/src/protobuf/WORKSPACE", line 65, column 20, in <toplevel>
                kotlin_repositories()
        File "/home/ubuntu/.cache/bazel/_bazel_ubuntu/f7c6c2b6616329c5799c427cd54ca291/external/io_bazel_rules_kotlin/src/main/starlark/core/repositories/initialize.bzl", line 96, column 21, in kotlin_repositories
                rules_repository(
Error in repository_rule: invalid user-provided repo name '': valid names may contain only A-Z, a-z, 0-9, '-', '_', '.', and must start with a letter
ERROR: Error computing the main repository mapping: at /home/ubuntu/.cache/bazel/_bazel_ubuntu/f7c6c2b6616329c5799c427cd54ca291/external/io_bazel_rules_kotlin/kotlin/core.bzl:2:5: at /home/ubuntu/.cache/bazel/_bazel_ubuntu/f7c6c2b6616329c5799c427cd54ca291/external/io_bazel_rules_kotlin/kotlin/internal/opts.bzl:16:5: Encountered error while reading extension file 'kotlin/opts.bzl': no such package '@@io_bazel_rules_kotlin_configured//kotlin': error loading package 'external': Could not load //external package
Computing main repo mapping:

Thanks.

lzhiyong commented 2 months ago

modify protobuf/CMakeLists.txt

# L298
# add android to include directory
# as follows
include_directories(
  ${ZLIB_INCLUDE_DIRECTORIES}
  ${protobuf_BINARY_DIR}
  ${protobuf_SOURCE_DIR}/src
  ${protobuf_SOURCE_DIR}/android)