• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<head>
4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5<title>F.A.Q.</title>
6<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
7<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
8<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
9<link rel="up" href="../boost_dll.html" title="Chapter 14. Boost.DLL">
10<link rel="prev" href="limitations.html" title="Limitations">
11<link rel="next" href="design_rationale.html" title="Design Rationale">
12</head>
13<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
14<table cellpadding="2" width="100%"><tr>
15<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
16<td align="center"><a href="../../../index.html">Home</a></td>
17<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
18<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
19<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
20<td align="center"><a href="../../../more/index.htm">More</a></td>
21</tr></table>
22<hr>
23<div class="spirit-nav">
24<a accesskey="p" href="limitations.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost_dll.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="design_rationale.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
25</div>
26<div class="section">
27<div class="titlepage"><div><div><h2 class="title" style="clear: both">
28<a name="boost_dll.f_a_q_"></a><a class="link" href="f_a_q_.html" title="F.A.Q.">F.A.Q.</a>
29</h2></div></div></div>
30<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
31          <span class="bold"><strong>Question:</strong></span> Is Boost.DLL thread-safe?
32          <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
33                <span class="bold"><strong>Answer:</strong></span> Some platforms allow concurrent
34                calls to <code class="computeroutput"><span class="identifier">dlopen</span></code> like
35                functions. For those platforms Boost.DLL is safe in the manner as
36                all the C++ Standard Library containers are: it is safe to use different
37                instances of shared_library from different threads even if all the
38                instances loaded the same library. On other platforms it is not safe
39                to concurrently call any of the functions from Boost.DLL (even a
40                <code class="computeroutput"><span class="identifier">shared_library</span><span class="special">::</span><span class="identifier">location</span><span class="special">()</span></code>
41                call triggers a race condition). See <a class="link" href="limitations.html#boost_dll.limitations.multithread" title="Thread safe library loading (Fails on FreeBSD, MacOS, iOS and some other)">Limitations,
42                Thread safe library loading</a>.
43              </li></ul></div>
44        </li></ul></div>
45<pre class="programlisting"></pre>
46<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
47          <span class="bold"><strong>Question:</strong></span> Why on Linux symbols from one
48          plugin are seen in another? Can't get symbol with same name from right
49          plugin!
50          <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
51                <span class="bold"><strong>Answer:</strong></span> You've run into the symbol
52                shadowing problem. Compile your plugins with "-fvisibility=hidden"
53                flag and take a look to the Tutorial section.
54              </li></ul></div>
55        </li></ul></div>
56<pre class="programlisting"></pre>
57<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
58          <span class="bold"><strong>Question:</strong></span> How Unicode (Windows) is handled?
59          <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
60                <span class="bold"><strong>Answer:</strong></span> Boost.DLL supports Unicode,
61                so that you could provide Unicode paths to it.
62              </li></ul></div>
63        </li></ul></div>
64<pre class="programlisting"></pre>
65<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
66          <span class="bold"><strong>Question:</strong></span> Can I open an executable file?
67          <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
68                <span class="bold"><strong>Answer:</strong></span> Yes, you can. Symbols need
69                be exported using in the executable using <code class="computeroutput"><span class="identifier">BOOST_SYMBOL_EXPORT</span></code>
70                or <code class="computeroutput"><span class="identifier">BOOST_DLL_ALIAS</span></code>.
71                You can call <code class="computeroutput"><span class="identifier">shared_library</span><span class="special">(</span><span class="identifier">program_location</span><span class="special">())</span></code> to load yourself. Refer to the
72                Tutorial section for more info. You can also query executables, just
73                provide a path to the executable to <code class="computeroutput"><span class="identifier">library_info</span></code>
74                class.
75              </li></ul></div>
76        </li></ul></div>
77<pre class="programlisting"></pre>
78<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
79          <span class="bold"><strong>Question:</strong></span> What if I specify wrong type
80          in <code class="computeroutput"><span class="identifier">shared_library</span><span class="special">::</span><span class="identifier">get</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code>
81          or <code class="computeroutput"><span class="identifier">import</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code>?
82          <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
83                <span class="bold"><strong>Answer:</strong></span> Usually you'll end up with
84                <code class="computeroutput"><span class="identifier">Segmentation</span> <span class="identifier">Fault</span></code>.
85                However it is safe to make types more strict, for example making
86                <code class="computeroutput"><span class="keyword">const</span> <span class="keyword">int</span></code>
87                from an <code class="computeroutput"><span class="keyword">int</span></code> will not
88                harm.
89              </li></ul></div>
90        </li></ul></div>
91<pre class="programlisting"></pre>
92<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
93          <span class="bold"><strong>Question:</strong></span> Does your library guarantee
94          ABI stability of methods?
95          <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
96                <span class="bold"><strong>Answer:</strong></span> Library only guarantees
97                that alias names created using the <code class="computeroutput"><span class="identifier">BOOST_DLL_ALIAS</span></code>
98                macros will not change with the change of compiler or platform. You
99                must take care of functions ABI and API stability by your own.
100              </li></ul></div>
101        </li></ul></div>
102<pre class="programlisting"></pre>
103<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
104          <span class="bold"><strong>Question:</strong></span> Are there any function signature
105          restrictions for the exported/imported functions?
106          <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
107                <span class="bold"><strong>Answer:</strong></span> No. You may import/export
108                functions with any signature and any return parameter.
109              </li></ul></div>
110        </li></ul></div>
111<pre class="programlisting"></pre>
112<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
113          <span class="bold"><strong>Question:</strong></span> I have 2 plugins that use same
114          shared library. Would be the shared library loaded twice?
115          <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
116                <span class="bold"><strong>Answer:</strong></span> No. Pugins will share the
117                shared library instance.
118              </li></ul></div>
119        </li></ul></div>
120<pre class="programlisting"></pre>
121<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
122          <span class="bold"><strong>Question:</strong></span> I have 2 plugins each of them
123          must work with it's own version of <code class="computeroutput"><span class="identifier">libsome_library</span></code>
124          shared library. How to achieve that?
125          <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
126                <span class="bold"><strong>Answer:</strong></span> Avoid such situations by
127                statically linking in the libsome_library into each plugin and loading
128                plugins with <code class="computeroutput"><span class="identifier">load_mode</span><span class="special">::</span><span class="identifier">rtld_deepbind</span></code>.
129              </li></ul></div>
130        </li></ul></div>
131<pre class="programlisting"></pre>
132<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
133          <span class="bold"><strong>Question:</strong></span> How to load a shared object
134          from memory??
135          <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
136                <span class="bold"><strong>Answer:</strong></span> All existing OS avoid loading
137                shared libraries directly from userspace memory, so you'll find no
138                syscall for such case. Currently Boost.DLL provides no means for
139                honest loading shared objects from memory. This requires reimplementing
140                dynamic linker logic in userspace for all the platforms, which is
141                a huge amount of work and very error-prone. However working patches
142                are welcomed!
143              </li></ul></div>
144        </li></ul></div>
145<p>
146      Workaround would be to write plugin into a temporary file in RAM and load plugin
147      from it:
148</p>
149<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">filesystem</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
150<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">dll</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span>
151<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">;</span>
152
153<span class="identifier">dll</span><span class="special">:</span><span class="identifier">shared_library</span> <span class="identifier">load_from_memory</span><span class="special">(</span><span class="keyword">unsigned</span> <span class="keyword">char</span><span class="special">*</span> <span class="identifier">data</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">size</span><span class="special">,</span> <span class="keyword">const</span> <span class="identifier">filesystem</span><span class="special">::</span><span class="identifier">path</span><span class="special">&amp;</span> <span class="identifier">tmp_plugin_path</span> <span class="special">=</span> <span class="identifier">filesystem</span><span class="special">::</span><span class="identifier">unique_path</span><span class="special">()</span> <span class="special">/</span> <span class="string">"libplugin.so"</span><span class="special">)</span> <span class="special">{</span>
154    <span class="keyword">const</span> <span class="identifier">filesystem</span><span class="special">::</span><span class="identifier">path</span> <span class="identifier">plugin_location</span> <span class="special">=</span> <span class="identifier">filesystem</span><span class="special">::</span><span class="identifier">temp_directory_path</span><span class="special">()</span> <span class="special">/</span> <span class="identifier">tmp_plugin_path</span><span class="special">;</span>
155    <span class="identifier">filesystem</span><span class="special">::</span><span class="identifier">create_directories</span><span class="special">(</span><span class="identifier">plugin_location</span><span class="special">.</span><span class="identifier">parent_path</span><span class="special">());</span>
156    <span class="identifier">filesystem</span><span class="special">::</span><span class="identifier">ofstream</span> <span class="identifier">ofs</span><span class="special">(</span><span class="identifier">plugin_location</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">ios</span><span class="special">::</span><span class="identifier">out</span><span class="special">|</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">ios</span><span class="special">::</span><span class="identifier">bin</span><span class="special">|</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">ios</span><span class="special">::</span><span class="identifier">trunc</span><span class="special">);</span>
157    <span class="identifier">ofs</span><span class="special">.</span><span class="identifier">write</span><span class="special">(</span><span class="identifier">data</span><span class="special">,</span> <span class="identifier">size</span><span class="special">);</span>
158
159    <span class="keyword">return</span> <span class="identifier">dll</span><span class="special">::</span><span class="identifier">shared_library</span><span class="special">(</span><span class="identifier">plugin_location</span><span class="special">);</span>
160<span class="special">}</span>
161</pre>
162<p>
163    </p>
164<p>
165      But there's no guarantee that <code class="computeroutput"><span class="identifier">filesystem</span><span class="special">::</span><span class="identifier">temp_directory_path</span><span class="special">()</span></code> will actually write to RAM, that's very platform
166      dependent.
167    </p>
168<pre class="programlisting"></pre>
169<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
170          <span class="bold"><strong>Question:</strong></span> I have found a bug, how do I
171          notify?
172          <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
173                <span class="bold"><strong>Answer:</strong></span> Create an <a href="https://github.com/apolukhin/Boost.DLL/issues" target="_top">issue
174                at GitHub</a> with a detailed description.
175              </li></ul></div>
176        </li></ul></div>
177</div>
178<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
179<td align="left"></td>
180<td align="right"><div class="copyright-footer">Copyright © 2014 Renato Tegon Forti, Antony Polukhin<br>Copyright © 2015 Antony Polukhin<br>Copyright © 2016 Antony Polukhin, Klemens Morgenstern<br>Copyright © 2017-2019 Antony Polukhin<p>
181        Distributed under the Boost Software License, Version 1.0. (See accompanying
182        file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
183      </p>
184</div></td>
185</tr></table>
186<hr>
187<div class="spirit-nav">
188<a accesskey="p" href="limitations.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../boost_dll.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="design_rationale.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
189</div>
190</body>
191</html>
192