6

I have a similar problem as How to add external header files during bazel/tensorflow build. but I hope there is a better solution.

I have a module that requires some external .h header files at other location. Suppose I try to include "vendor/external/include/thirdpary.h", In Android.bp, I add some line like:

include_dirs: [
"vendor/external/include",
]

But the compiler is complaining this file does not exist when I include it in my CPP file:

#include "thirdpary.h"
user2271769
  • 181
  • 2
  • 7

3 Answers3

3

Using include_dirs is the correct approach. From what you write in your description it should work.

Here are some suggestions for error checking:

Is vendor/external/include actually a subfolder of $ANDROID_BUILD_TOP?

Directories in include_dirs have to be specified relatively to the AOSP root directory. If the path is relative to your Android.bp you have to use local_include_dirs instead.

cc_binary {
    name: "my-module",
    srcs: [ "main.cpp" ],
    include_dirs: [ "vendor/external/include" ]
}

Is the cpp file in the srcs list of the same module definition as include_dirs?

If you want to inherit the include directory from a library your module depends on, then the library should use export_include_dirs.

cc_library {
    name: "my-library",
    export_include_dirs: [ "include" ]
}

cc_binary {
    name: "my-module",
    srcs: [ "main.cpp" ],
    static_libs: [ "my-library"] 
}

What include dirs are provided to the compiler when you build your module?

Rebuild your module and check the -I options.

m my-module | grep "main.cpp" | sed 's/-I/\n-I/g'
Simpl
  • 1,938
  • 1
  • 10
  • 21
0

simply include the header files of the library via

#include "/path/to/library/header.h"

and then use LIBS in your *.pro file.

Hagar Magdy
  • 293
  • 2
  • 10
0

In the above code "thirdpary.h" file will not be referenced or included that's why getting the above issue.

So to resolve the above issue, give the relative path. like below code snippet:

if the header file path in dir structure is:

com/example/abc/header.h

like this and in implementation if it's only using

#include "thirdpary.h"

then you need to give path till the header file dir.

include_dirs: [
    "vendor/external/include/com/example/abc",
    ]

Hope this will resolve the issue.