[英]Android rebuilds static library when the binary is compiled
I have a binary in Android that links to a static library A. Static library libA depends on multiple shared libraries.我在 Android 中有一个二进制文件,它链接到 static 库 A. Static 库libA依赖于多个共享库。 The binary does not do anything except it imports a class from the static library and executes a simple function.
除了从 static 库中导入 class 并执行简单的 function 之外,该二进制文件不执行任何操作。
However, the binary fails to build except I link against the same shared libraries to which the static library A is linked because the compiler tries to recompile libA with the build config of the binary.但是,除了我链接到与 static 库 A 链接到的相同共享库之外,二进制文件无法构建,因为编译器尝试使用二进制文件的构建配置重新编译libA 。
Here is my Android.bp of the static library:这是我的 static 库的 Android.bp :
cc_library_static {
name: "libA",
relative_install_path: "hw",
vendor: true,
rtti: true,
cflags: [
"-Wall",
"-Wextra",
"-g",
"-DUNIT_TEST",
"-fexceptions"
],
srcs: [
"libA.cpp",
],
shared_libs: [
"libhidlbase",
"libhidltransport",
"libutils",
"liblog"
],
header_libs: [
"lib_a_stub_headers",
],
whole_static_libs: [
"lib_a_stub",
],
export_include_dirs: ["."]
}
Here is my Android.bp for the binary:这是我的 Android.bp 二进制文件:
cc_binary{
name: "simplebinary",
relative_install_path: "hw",
vendor: true,
cflags: [
"-fexceptions"
],
whole_static_libs: [
"libA"
],
shared_libs: [
"vendor.test.hal@1.0",
],
srcs: [
"simplebinary.cpp",
],
}
The build of the binary fails with:二进制文件的构建失败:
libA.hpp:4:10: fatal error: 'lib/lib.hpp' file not found
I'm building using the command mm
我正在使用命令
mm
构建
According to the error message, the compiler cannot find a header file in its header search path.根据错误信息,编译器在其 header 搜索路径中找不到 header 文件。 Header includes are resolved during the preprocessor stage, therefore this is not a linking problem.
Header 包含在预处理器阶段解决,因此这不是链接问题。 The preprocessor runs at the beginning of compilation, the linking is done at the end.
预处理器在编译开始时运行,链接在最后完成。
From your description, I understand that the code for simplebinary
includes the header libA.hpp
, provided by libA
.根据您的描述,我了解到
simplebinary
的代码包括由libA.hpp
提供的libA
。 I understand that libA.hpp
is contained in the same directory as the Android.bp
that defines the libA
module.我知道
libA.hpp
与定义libA
模块的Android.bp
包含在同一目录中。 Because of the export_include_dirs: ["."]
, this directory is added to the header search path for the compilation of simplebinary
.由于
export_include_dirs: ["."]
,该目录被添加到 header 搜索路径中,用于编译simplebinary
。 Therefore, the compiler can find libA.hpp
when compiling simplebinary
.因此,编译器在编译
simplebinary
libA.hpp
Now libA.hpp
includes CommonAPI/CommonAPI.hpp
.现在
libA.hpp
包括CommonAPI/CommonAPI.hpp
。 I do not know to which library this header belongs.我不知道这个 header 属于哪个库。 I assume the header belongs to some library
libB
, and libA
links against libB
.我假设 header 属于某个库
libB
,并且libA
链接到libB
。 I further assume that libB
has export_include_dirs
set to point to the folder containing CommonAPI/CommonAPI.hpp
.我进一步假设
libB
已将export_include_dirs
设置为指向包含CommonAPI/CommonAPI.hpp
的文件夹。 You can then make libA
re-export this header by adding export_shared_lib_headers: ["libB"]
to the module declaration of libA
.然后,您可以通过将
export_shared_lib_headers: ["libB"]
添加到 libA 的模块声明来使libA
重新导出此libA
。 If libB
is not a shared library, you would have to use export_static_lib_headers
or export_header_lib_headers
instead ( reference ).如果
libB
不是共享库,则必须改用export_static_lib_headers
或export_header_lib_headers
( 参考)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.