0

I have a C++ static library A and a C++ shared library B(Android HAL). I want to have a pointer to an instance of class A inside class B and a pointer to an instance of class B inside class A.

The purpose of this is to have multi-directional communication between the two instances. Registration of callbacks is not an option because of multiple callbacks with different signatures. class A:

cc_library_static {
    name: "static_lib_A",
    relative_install_path: "hw",
    vendor: true,

    shared_libs: [
         "shared_lib_B"
    ],
    
    srcs: [
         "staticLibA.cpp"
    ]
}

class B:

cc_library_shared {
    name: "shared_lib_B",
    vendor: true,

    whole_static_libs: [
         "static_lib_A
    ],
    
    srcs: [
         "sharedLibB.cpp"
    ]
}

Both classes cannot be bundled in one library because one is compiled using RTTI and the other is not.

This causes a cyclic dependency error. Is there a way to resolve this?

Thanks.

Moaaz Ali
  • 93
  • 15
  • Thank you. However, in the example provided they both include one header file. In my case, they are two different libraries and they cannot be mixed in one library. One of them is compiled using RTTI and the other is not. – Moaaz Ali Sep 04 '20 at 10:30
  • Forward declaration is the key to solve it. – πάντα ῥεῖ Sep 04 '20 at 10:31
  • They cannot be bundled in header, they are different libraries and has to be that way – Moaaz Ali Sep 04 '20 at 10:35
  • I didn't say you should bundle in headers. Did you read the other duplicate link already? Just forward declare in one, and include the necessary header in the corresponding compilaiton unit. Otherwise, you can't do what you want, unless you wrap up the whole stuff in a 3rd component, no matter if you say _it has to be that way_. – πάντα ῥεῖ Sep 04 '20 at 10:38

0 Answers0