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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>F.A.Q.</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../boost_dll.html" title="Chapter 12. Boost.DLL">
<link rel="prev" href="limitations.html" title="Limitations">
<link rel="next" href="design_rationale.html" title="Design Rationale">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<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>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="boost_dll.f_a_q_"></a><a class="link" href="f_a_q_.html" title="F.A.Q.">F.A.Q.</a>
</h2></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
<span class="bold"><strong>Question:</strong></span> Is Boost.DLL thread-safe?
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
<span class="bold"><strong>Answer:</strong></span> Some platforms allow concurrent
calls to <code class="computeroutput"><span class="identifier">dlopen</span></code> like
functions. For those platforms Boost.DLL is safe in the manner as
all the C++ Standard Library containers are: it is safe to use different
instances of shared_library from different threads even if all the
instances loaded the same library. On other platforms it is not safe
to concurrently call any of the functions from Boost.DLL (even a
<code class="computeroutput"><span class="identifier">shared_library</span><span class="special">::</span><span class="identifier">location</span><span class="special">()</span></code>
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,
Thread safe library loading</a>.
</li></ul></div>
</li></ul></div>
<pre class="programlisting"></pre>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
<span class="bold"><strong>Question:</strong></span> Why on Linux symbols from one
plugin are seen in another? Can't get symbol with same name from right
plugin!
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
<span class="bold"><strong>Answer:</strong></span> You've run into the symbol
shadowing problem. Compile your plugins with "-fvisibility=hidden"
flag and take a look to the Tutorial section.
</li></ul></div>
</li></ul></div>
<pre class="programlisting"></pre>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
<span class="bold"><strong>Question:</strong></span> How Unicode (Windows) is handled?
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
<span class="bold"><strong>Answer:</strong></span> Boost.DLL supports Unicode,
so that you could provide Unicode paths to it.
</li></ul></div>
</li></ul></div>
<pre class="programlisting"></pre>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
<span class="bold"><strong>Question:</strong></span> Can I open an executable file?
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
<span class="bold"><strong>Answer:</strong></span> Yes, you can. Symbols need
be exported using in the executable using <code class="computeroutput"><span class="identifier">BOOST_SYMBOL_EXPORT</span></code>
or <code class="computeroutput"><span class="identifier">BOOST_DLL_ALIAS</span></code>.
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
Tutorial section for more info. You can also query executables, just
provide a path to the executable to <code class="computeroutput"><span class="identifier">library_info</span></code>
class.
</li></ul></div>
</li></ul></div>
<pre class="programlisting"></pre>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
<span class="bold"><strong>Question:</strong></span> What if I specify wrong type
in <code class="computeroutput"><span class="identifier">shared_library</span><span class="special">::</span><span class="identifier">get</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code>
or <code class="computeroutput"><span class="identifier">import</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code>?
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
<span class="bold"><strong>Answer:</strong></span> Usually you'll end up with
<code class="computeroutput"><span class="identifier">Segmentation</span> <span class="identifier">Fault</span></code>.
However it is safe to make types more strict, for example making
<code class="computeroutput"><span class="keyword">const</span> <span class="keyword">int</span></code>
from an <code class="computeroutput"><span class="keyword">int</span></code> will not
harm.
</li></ul></div>
</li></ul></div>
<pre class="programlisting"></pre>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
<span class="bold"><strong>Question:</strong></span> Does your library guarantee
ABI stability of methods?
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
<span class="bold"><strong>Answer:</strong></span> Library only guarantees
that alias names created using the <code class="computeroutput"><span class="identifier">BOOST_DLL_ALIAS</span></code>
macros will not change with the change of compiler or platform. You
must take care of functions ABI and API stability by your own.
</li></ul></div>
</li></ul></div>
<pre class="programlisting"></pre>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
<span class="bold"><strong>Question:</strong></span> Are there any function signature
restrictions for the exported/imported functions?
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
<span class="bold"><strong>Answer:</strong></span> No. You may import/export
functions with any signature and any return parameter.
</li></ul></div>
</li></ul></div>
<pre class="programlisting"></pre>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
<span class="bold"><strong>Question:</strong></span> I have 2 plugins that use same
shared library. Would be the shared library loaded twice?
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
<span class="bold"><strong>Answer:</strong></span> No. Pugins will share the
shared library instance.
</li></ul></div>
</li></ul></div>
<pre class="programlisting"></pre>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
<span class="bold"><strong>Question:</strong></span> I have 2 plugins each of them
must work with it's own version of <code class="computeroutput"><span class="identifier">libsome_library</span></code>
shared library. How to achieve that?
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
<span class="bold"><strong>Answer:</strong></span> Avoid such situations by
statically linking in the libsome_library into each plugin and loading
plugins with <code class="computeroutput"><span class="identifier">load_mode</span><span class="special">::</span><span class="identifier">rtld_deepbind</span></code>.
</li></ul></div>
</li></ul></div>
<pre class="programlisting"></pre>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
<span class="bold"><strong>Question:</strong></span> How to load a shared object
from memory??
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
<span class="bold"><strong>Answer:</strong></span> All existing OS avoid loading
shared libraries directly from userspace memory, so you'll find no
syscall for such case. Currently Boost.DLL provides no means for
honest loading shared objects from memory. This requires reimplementing
dynamic linker logic in userspace for all the platforms, which is
a huge amount of work and very error-prone. However working patches
are welcomed!
</li></ul></div>
</li></ul></div>
<p>
Workaround would be to write plugin into a temporary file in RAM and load plugin
from it:
</p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</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">></span>
<span class="preprocessor">#include</span> <span class="special"><</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">></span>
<span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">;</span>
<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">&</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>
<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>
<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>
<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>
<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>
<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>
<span class="special">}</span>
</pre>
<p>
</p>
<p>
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
dependent.
</p>
<pre class="programlisting"></pre>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem">
<span class="bold"><strong>Question:</strong></span> I have found a bug, how do I
notify?
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem">
<span class="bold"><strong>Answer:</strong></span> Create an <a href="https://github.com/apolukhin/Boost.DLL/issues" target="_top">issue
at GitHub</a> with a detailed description.
</li></ul></div>
</li></ul></div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<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<p>
Distributed under the Boost Software License, Version 1.0. (See accompanying
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<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>
</div>
</body>
</html>
|