xref: /aosp_15_r20/external/libbrillo/brillo/brillo_export.h (revision 1a96fba65179ea7d3f56207137718607415c5953)
1*1a96fba6SXin Li // Copyright 2014 The Chromium OS Authors. All rights reserved.
2*1a96fba6SXin Li // Use of this source code is governed by a BSD-style license that can be
3*1a96fba6SXin Li // found in the LICENSE file.
4*1a96fba6SXin Li 
5*1a96fba6SXin Li #ifndef LIBBRILLO_BRILLO_BRILLO_EXPORT_H_
6*1a96fba6SXin Li #define LIBBRILLO_BRILLO_BRILLO_EXPORT_H_
7*1a96fba6SXin Li 
8*1a96fba6SXin Li // Use BRILLO_EXPORT attribute to decorate your classes, methods and variables
9*1a96fba6SXin Li // that need to be exported out of libbrillo. By default, any symbol not
10*1a96fba6SXin Li // explicitly marked with BRILLO_EXPORT attribute is not exported.
11*1a96fba6SXin Li 
12*1a96fba6SXin Li // Put BRILLO_EXPORT in front of methods or variables and in between the
13*1a96fba6SXin Li // class and the tag name:
14*1a96fba6SXin Li /*
15*1a96fba6SXin Li 
16*1a96fba6SXin Li BRILLO_EXPORT void foo();
17*1a96fba6SXin Li 
18*1a96fba6SXin Li class BRILLO_EXPORT Bar {
19*1a96fba6SXin Li  public:
20*1a96fba6SXin Li   void baz();  // Exported since it is a member of an exported class.
21*1a96fba6SXin Li };
22*1a96fba6SXin Li 
23*1a96fba6SXin Li */
24*1a96fba6SXin Li 
25*1a96fba6SXin Li // Exporting a class automatically exports all of its members. However there are
26*1a96fba6SXin Li // no export entries for non-static member variables since they are not accessed
27*1a96fba6SXin Li // directly, but rather through "this" pointer. Class methods, type information,
28*1a96fba6SXin Li // virtual table (if any), and static member variables are exported.
29*1a96fba6SXin Li 
30*1a96fba6SXin Li // Finally, template functions and template members of a class may not be
31*1a96fba6SXin Li // inlined by the compiler automatically and the out-of-line version will not
32*1a96fba6SXin Li // be exported and fail to link. Marking those inline explicitly might help.
33*1a96fba6SXin Li // Alternatively, exporting specific instantiation of the template could be
34*1a96fba6SXin Li // used with "extern template" and combining this with BRILLO_EXPORT.
35*1a96fba6SXin Li #define BRILLO_EXPORT __attribute__((__visibility__("default")))
36*1a96fba6SXin Li 
37*1a96fba6SXin Li // On occasion you might need to disable exporting a particular symbol if
38*1a96fba6SXin Li // you don't want the clients to see it. For example, you can explicitly
39*1a96fba6SXin Li // hide a member of an exported class:
40*1a96fba6SXin Li /*
41*1a96fba6SXin Li 
42*1a96fba6SXin Li class BRILLO_EXPORT Foo {
43*1a96fba6SXin Li  public:
44*1a96fba6SXin Li   void bar();  // Exported since it is a member of an exported class.
45*1a96fba6SXin Li 
46*1a96fba6SXin Li  private:
47*1a96fba6SXin Li   BRILLO_PRIVATE void baz();  // Explicitly removed from export table.
48*1a96fba6SXin Li };
49*1a96fba6SXin Li 
50*1a96fba6SXin Li */
51*1a96fba6SXin Li 
52*1a96fba6SXin Li // Note that even though a class may have a private member it doesn't mean
53*1a96fba6SXin Li // that it must not be exported, since the compiler might still need it.
54*1a96fba6SXin Li // For example, an inline public method calling a private method will not link
55*1a96fba6SXin Li // if that private method is not exported.
56*1a96fba6SXin Li // So be careful with hiding members if you don't want to deal with obscure
57*1a96fba6SXin Li // linker errors.
58*1a96fba6SXin Li #define BRILLO_PRIVATE __attribute__((__visibility__("hidden")))
59*1a96fba6SXin Li 
60*1a96fba6SXin Li #endif  // LIBBRILLO_BRILLO_BRILLO_EXPORT_H_
61