我和How to add external header files during bazel/tensorflow build也有类似的问题。但我希望有更好的解决方案。
我有一个在其他位置需要一些外部.h头文件的模块。假设我尝试在Android.bp中包含"vendor/external/ include /thirdpary.h",我添加如下行:
include_dirs: [
"vendor/external/include",
]
但是当我将这个文件包含在我的CPP文件中时,编译器却报告这个文件不存在:
#include "thirdpary.h"
发布于 2020-01-14 20:06:40
使用include_dirs
是正确的方法。从您在描述中所写的内容来看,它应该是有效的。
以下是错误检查的一些建议:
vendor/external/include
实际上是$ANDROID_BUILD_TOP
的子文件夹吗
include_dirs
中的目录必须相对于AOSP根目录进行指定。如果该路径是相对于您的Android.bp
的,则必须使用local_include_dirs
。
cc_binary {
name: "my-module",
srcs: [ "main.cpp" ],
include_dirs: [ "vendor/external/include" ]
}
是与include_dirs
具有相同模块定义的srcs
列表中的cpp文件
如果您希望从模块所依赖的库继承include目录,那么该库应该使用export_include_dirs
。
cc_library {
name: "my-library",
export_include_dirs: [ "include" ]
}
cc_binary {
name: "my-module",
srcs: [ "main.cpp" ],
static_libs: [ "my-library"]
}
当你构建你的模块时,提供给编译器的包含目录是什么?
重新构建模块并检查-I
选项。
m my-module | grep "main.cpp" | sed 's/-I/\n-I/g'
发布于 2020-01-14 18:07:32
只需通过以下方式包含库的头文件
#include "/path/to/library/header.h"
然后在*.pro文件中使用LIBS。
发布于 2020-08-07 16:40:03
在上面的代码中,"thirdpary.h“文件将不会被引用或包含,这就是为什么会出现上述问题。
因此,要解决上述问题,请给出相对路径。就像下面的代码片段:
如果dir结构中的头文件路径为:
示例com/
/abc/header.h
在实现中,如果它只使用
#包含"thirdpary.h“
然后你需要给出头文件dir的路径。
include_dirs: [
"vendor/external/include/com/example/abc",
]
希望这能解决这个问题。
https://stackoverflow.com/questions/53606445
复制相似问题