This file is indexed.

/usr/share/qt5/doc/qtdoc/sharedlibrary.html is in qt5-doc-html 5.5.1-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- sharedlibrary.qdoc -->
  <title>Creating Shared Libraries | Qt 5.5 </title>
  <link rel="stylesheet" type="text/css" href="style/offline.css" />
</head>
<body>
<div class="header" id="qtdocheader">
    <div class="main">
    <div class="main-rounded">
        <div class="navigationbar">
        <ul>
<li><a href="index.html">Qt 5.5</a></li>
<li>Creating Shared Libraries</li>
<li id="buildversion">Qt 5.5.1 Reference Documentation</li>
    </ul>
    </div>
</div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level1"><a href="#using-symbols-from-shared-libraries">Using Symbols from Shared Libraries</a></li>
<li class="level1"><a href="#header-file-considerations">Header File Considerations</a></li>
<li class="level1"><a href="#binary-compatibility">Binary Compatibility</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Creating Shared Libraries</h1>
<span class="subtitle"></span>
<!-- $$$sharedlibrary.html-description -->
<div class="descr"> <a name="details"></a>
<p>The following sections list certain things that should be taken into account when creating shared libraries.</p>
<a name="using-symbols-from-shared-libraries"></a>
<h2 id="using-symbols-from-shared-libraries">Using Symbols from Shared Libraries</h2>
<p>Symbols - functions, variables or classes - contained in shared libraries intended to be used by <i>clients</i>, such as applications or other libraries, must be marked in a special way. These symbols are called <i>public symbols</i> that are <i>exported</i> or made publicly visible.</p>
<p>The remaining symbols should not be visible from the outside. On most platforms, compilers will hide them by default. On some platforms, a special compiler option is required to hide these symbols.</p>
<p>When compiling a shared library, it must be marked for <i>export</i>. To use the shared library from a client, some platforms may require a special <i>import</i> declaration as well.</p>
<p>Depending on your target platform, Qt provides special macros that contain the necessary definitions:</p>
<ul>
<li><code>Q_DECL_EXPORT</code> must be added to the declarations of symbols used when compiling a shared library.</li>
<li><code>Q_DECL_IMPORT</code> must be added to the declarations of symbols used when compiling a client that uses the shared library.</li>
</ul>
<p>Now, we need to ensure that the right macro is invoked -- whether we compile a shared library itself, or just the client using the shared library. Typically, this can be solved by adding a special header.</p>
<p>Let us assume we want to create a shared library called <i>mysharedlib</i>. A special header for this library, <code>mysharedlib_global.h</code>, looks like this:</p>
<pre class="cpp"><span class="preprocessor">#include &lt;QtCore/QtGlobal&gt;</span>

<span class="preprocessor">#if defined(MYSHAREDLIB_LIBRARY)</span>
<span class="preprocessor">#  define MYSHAREDLIB_EXPORT Q_DECL_EXPORT</span>
<span class="preprocessor">#else</span>
<span class="preprocessor">#  define MYSHAREDLIB_EXPORT Q_DECL_IMPORT</span>
<span class="preprocessor">#endif</span></pre>
<p>In the <code>.pro</code> file of the shared library, we add:</p>
<pre class="cpp">DEFINES <span class="operator">+</span><span class="operator">=</span> MYSHAREDLIB_LIBRARY</pre>
<p>In each header of the library, we specify the following:</p>
<pre class="cpp"><span class="preprocessor">#include &quot;mysharedlib_global.h&quot;</span>

MYSHAREDLIB_EXPORT <span class="type">void</span> foo();
<span class="keyword">class</span> MYSHAREDLIB_EXPORT MyClass<span class="operator">.</span><span class="operator">.</span><span class="operator">.</span></pre>
<p>This ensures that the right macro is seen by both library and clients. We also use this technique in Qt's sources.</p>
<a name="header-file-considerations"></a>
<h2 id="header-file-considerations">Header File Considerations</h2>
<p>Typically, clients will include only the public header files of shared libraries. These libraries might be installed in a different location, when deployed. Therefore, it is important to exclude other internal header files that were used when building the shared library.</p>
<p>For example, the library might provide a class that wraps a hardware device and contains a handle to that device, provided by some 3rd-party library:</p>
<pre class="cpp"><span class="preprocessor">#include &lt;footronics/device.h&gt;</span>

<span class="keyword">class</span> MyDevice {
<span class="keyword">private</span>:
    FOOTRONICS_DEVICE_HANDLE handle;
};</pre>
<p>A similar situation arises with forms created by Qt Designer when using aggregation or multiple inheritance:</p>
<pre class="cpp"><span class="preprocessor">#include &quot;ui_widget.h&quot;</span>

<span class="keyword">class</span> MyWidget : <span class="keyword">public</span> <span class="type"><a href="../qtwidgets/qwidget.html">QWidget</a></span> {
<span class="keyword">private</span>:
    Ui<span class="operator">::</span>MyWidget m_ui;
};</pre>
<p>When deploying the library, there should be no dependency to the internal headers <code>footronics/device.h</code> or <code>ui_widget.h</code>.</p>
<p>This can be avoided by making use of the <i>Pointer to implementation</i> idiom described in various C++ programming books. For classes with <i>value semantics</i>, consider using <a href="../qtcore/qshareddatapointer.html">QSharedDataPointer</a>.</p>
<a name="binary-compatibility"></a>
<h2 id="binary-compatibility">Binary Compatibility</h2>
<p>For clients loading a shared library, to work correctly, the memory layout of the classes being used must match exactly the memory layout of the library version that was used to compile the client. In other words, the library found by the client at runtime must be <i>binary compatible</i> with the version used at compile time.</p>
<p>This is usually not a problem if the client is a self-contained software package that ships all the libraries it needs.</p>
<p>However, if the client application relies on a shared library that belongs to a different installation package or to the operating system, then we need to think of a versioning scheme for shared libraries and decide at which level <i>Binary compatibility</i> is to be maintained. For example, Qt libraries of the same <i>major version number</i> are guaranteed to be binary compatible.</p>
<p>Maintaining <i>Binary compatibility</i> places some restrictions on the changes you can make to the classes. A good explanation can be found at <a href="http://techbase.kde.org/Policies/Binary_Compatibility_Issues_With_C++">KDE - Policies/Binary Compatibility Issues With C++</a>. These issues should be considered right from the start of library design. We recommend that the principle of <i>Information hiding</i> and the <i>Pointer to implementation</i> technique be used wherever possible.</p>
</div>
<!-- @@@sharedlibrary.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2015 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>