mirror of https://github.com/tLDP/LDP
updated
This commit is contained in:
parent
945b362ef6
commit
822ebb357e
|
@ -1,7 +1,6 @@
|
|||
<?xml version="1.0" encoding="ISO-8859-1"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
|
||||
"http://docbook.org/xml/4.2/docbookx.dtd" [
|
||||
]>
|
||||
"http://docbook.org/xml/4.2/docbookx.dtd">
|
||||
<article>
|
||||
|
||||
<articleinfo>
|
||||
|
@ -16,15 +15,17 @@
|
|||
</affiliation>
|
||||
</author>
|
||||
|
||||
<pubdate>2002-06-30</pubdate>
|
||||
|
||||
<releaseinfo>$Id$</releaseinfo>
|
||||
<pubdate>2003-08-12</pubdate>
|
||||
|
||||
<revhistory>
|
||||
|
||||
<!-- I only keep the last 5 revision updates here; I keep the
|
||||
document in CVS, if you're interested in more exact change logs
|
||||
you can email me. -->
|
||||
<revision>
|
||||
<revnumber>1.03</revnumber>
|
||||
<date>2003-08-12</date>
|
||||
<authorinitials>AI</authorinitials>
|
||||
<revremark>Added reference to the GLib Dynamic Module
|
||||
Loader. Thanks to G. V. Sriraam for the pointer.</revremark>
|
||||
</revision>
|
||||
|
||||
<revision>
|
||||
<revnumber>1.02</revnumber>
|
||||
|
@ -73,16 +74,14 @@
|
|||
</revhistory>
|
||||
|
||||
<abstract>
|
||||
<para>
|
||||
How to dynamically load C++ functions and classes using the
|
||||
<function>dlopen</function> API.
|
||||
</para>
|
||||
<para>How to dynamically load C++ functions and classes using
|
||||
the <function>dlopen</function> API.</para>
|
||||
</abstract>
|
||||
|
||||
</articleinfo>
|
||||
|
||||
|
||||
<sect1 id="intro">
|
||||
<section id="intro">
|
||||
<title>Introduction</title>
|
||||
|
||||
<para>
|
||||
|
@ -102,7 +101,7 @@
|
|||
<para>This HOWTO's master location is <ulink
|
||||
url="http://www.isotton.com/howtos/C++-dlopen-mini-HOWTO/"/>.</para>
|
||||
|
||||
<sect2 id="copyright">
|
||||
<section id="copyright">
|
||||
<title>Copyright and License</title>
|
||||
|
||||
<para>
|
||||
|
@ -114,9 +113,9 @@
|
|||
Free Software Foundation; with no Invariant Sections, with no
|
||||
Front-Cover Texts, and with no Back-Cover Texts.
|
||||
</para>
|
||||
</sect2>
|
||||
</section>
|
||||
|
||||
<sect2 id="disclaimer">
|
||||
<section id="disclaimer">
|
||||
<title>Disclaimer</title>
|
||||
|
||||
<para>
|
||||
|
@ -135,9 +134,9 @@
|
|||
any trademark or service mark. Naming of particular products
|
||||
or brands should not be seen as endorsements.
|
||||
</para>
|
||||
</sect2>
|
||||
</section>
|
||||
|
||||
<sect2 id="credits">
|
||||
<section id="credits">
|
||||
<title>Credits / Contributors</title>
|
||||
|
||||
<para>
|
||||
|
@ -161,9 +160,9 @@
|
|||
|
||||
</itemizedlist>
|
||||
|
||||
</sect2>
|
||||
</section>
|
||||
|
||||
<sect2 id="feedback">
|
||||
<section id="feedback">
|
||||
<title>Feedback</title>
|
||||
|
||||
<para>
|
||||
|
@ -171,9 +170,9 @@
|
|||
your additions, comments and criticisms to the following email
|
||||
address: <email>aaron@isotton.com</email>.
|
||||
</para>
|
||||
</sect2>
|
||||
</section>
|
||||
|
||||
<sect2>
|
||||
<section>
|
||||
<title>Terms Used in this Document</title>
|
||||
|
||||
<variablelist>
|
||||
|
@ -196,10 +195,10 @@
|
|||
</varlistentry>
|
||||
</variablelist>
|
||||
|
||||
</sect2>
|
||||
</section>
|
||||
|
||||
<!-- Translations - ->
|
||||
<sect2 id="translations">
|
||||
<section id="translations">
|
||||
<title>Translations</title>
|
||||
|
||||
<para>
|
||||
|
@ -221,11 +220,11 @@
|
|||
</para>
|
||||
</listitem>
|
||||
</itemizedlist>
|
||||
</sect2>
|
||||
</section>
|
||||
-->
|
||||
</sect1>
|
||||
</section>
|
||||
|
||||
<sect1 id="theproblem">
|
||||
<section id="theproblem">
|
||||
<title>The Problem</title>
|
||||
|
||||
<para>At some time you might have to load a library (and use its
|
||||
|
@ -248,7 +247,7 @@
|
|||
even if you're not interested in it because it will help you
|
||||
understanding why problems occur and how to solve them.</para>
|
||||
|
||||
<sect2 id="mangling">
|
||||
<section id="mangling">
|
||||
<title>Name Mangling</title>
|
||||
|
||||
<para>In every C++ program (or library, or object file), all
|
||||
|
@ -287,9 +286,9 @@
|
|||
probably work with your compiler only, and might already be
|
||||
broken with the next version.</para>
|
||||
|
||||
</sect2>
|
||||
</section>
|
||||
|
||||
<sect2>
|
||||
<section>
|
||||
<title>Classes</title>
|
||||
|
||||
<para>Another problem with the <function>dlopen</function> API
|
||||
|
@ -299,14 +298,14 @@
|
|||
program. Obviously, to use that class you need to create an
|
||||
instance of it, but that cannot be easily done.</para>
|
||||
|
||||
</sect2>
|
||||
</section>
|
||||
|
||||
</sect1>
|
||||
</section>
|
||||
|
||||
<sect1 id="thesolution">
|
||||
<section id="thesolution">
|
||||
<title>The Solution</title>
|
||||
|
||||
<sect2 id="externC">
|
||||
<section id="externC">
|
||||
<title><literal>extern "C"</literal></title>
|
||||
|
||||
<para>C++ has a special keyword to declare a function with C
|
||||
|
@ -326,9 +325,9 @@
|
|||
code. Such a function is a full-featured C++ function which
|
||||
can use C++ features and take any type of argument.</para>
|
||||
|
||||
</sect2>
|
||||
</section>
|
||||
|
||||
<sect2 id="loadingfunctions">
|
||||
<section id="loadingfunctions">
|
||||
<title>Loading Functions</title>
|
||||
|
||||
<para>In C++ functions are loaded just like in C, with
|
||||
|
@ -387,7 +386,6 @@ extern "C" void hello() {
|
|||
std::cout << "hello" << '\n';
|
||||
}
|
||||
]]></programlisting>
|
||||
|
||||
</example>
|
||||
|
||||
<para>The function <function>hello</function> is defined in
|
||||
|
@ -411,8 +409,10 @@ extern "C" void hello() {
|
|||
<programlisting>extern "C" int foo;
|
||||
extern "C" void bar();
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
and
|
||||
<programlisting>extern "C" {
|
||||
<informalexample>
|
||||
<programlisting>extern "C" {
|
||||
extern int foo;
|
||||
extern void bar();
|
||||
}</programlisting>
|
||||
|
@ -427,11 +427,13 @@ extern "C" void bar();
|
|||
|
||||
<informalexample>
|
||||
<programlisting>extern "C" int foo;</programlisting>
|
||||
</informalexample>
|
||||
and
|
||||
<programlisting>extern "C" {
|
||||
<informalexample>
|
||||
<programlisting>extern "C" {
|
||||
int foo;
|
||||
}</programlisting>
|
||||
</informalexample>
|
||||
</informalexample>
|
||||
|
||||
are <emphasis>not</emphasis> the same thing.</para>
|
||||
|
||||
|
@ -446,9 +448,9 @@ extern "C" void bar();
|
|||
|
||||
</warning>
|
||||
|
||||
</sect2>
|
||||
</section>
|
||||
|
||||
<sect2 id="loadingclasses">
|
||||
<section id="loadingclasses">
|
||||
<title>Loading Classes</title>
|
||||
|
||||
<para>Loading classes is a bit more difficult because we need
|
||||
|
@ -618,10 +620,10 @@ extern "C" void destroy(polygon* p) {
|
|||
</listitem>
|
||||
</itemizedlist>
|
||||
|
||||
</sect2>
|
||||
</sect1>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
<sect1 id="faq">
|
||||
<section id="faq">
|
||||
<title>Frequently Asked Questions</title>
|
||||
<qandaset>
|
||||
<qandaentry>
|
||||
|
@ -635,28 +637,48 @@ extern "C" void destroy(polygon* p) {
|
|||
<filename>dlfcn.h</filename> header on Windows,and there is
|
||||
no <function>dlopen</function> API. There is a similar API
|
||||
around the <function>LoadLibrary</function> function, and
|
||||
most of what is written here applies to it, too. Refer to
|
||||
the Win32 Platform SDK documentation or have a look at
|
||||
<ulink url="http://msdn.microsoft.com">MSDN</ulink>.</para>
|
||||
most of what is written here applies to it, too.
|
||||
Alternatively, you can use libltdl (included in libtool) to
|
||||
<quote>emulate</quote> <function>dlopen</function> on a
|
||||
variety of platforms.</para>
|
||||
|
||||
<para>You should also read section 4, <quote>Dynamically
|
||||
Loaded (DL) Libraries</quote>, of the <ulink
|
||||
url="http://www.dwheeler.com/program-library">Program Library
|
||||
HOWTO</ulink> for more techniques to load libraries and
|
||||
create classes independently of your platform.</para>
|
||||
</answer>
|
||||
</qandaentry>
|
||||
|
||||
<qandaentry>
|
||||
<question>
|
||||
<para>Is there some kind of
|
||||
<function>dlopen</function>-compatible wrapper for the
|
||||
Windows <function>LoadLibrary</function> API?</para>
|
||||
<question>
|
||||
|
||||
<para>Is there some kind of <function>dlopen</function>-compatible
|
||||
wrapper for the Windows <function>LoadLibrary</function>
|
||||
API?</para>
|
||||
|
||||
</question>
|
||||
<answer>
|
||||
<para>I don't know, and honestly I don't care. If you know
|
||||
of something, feel free mailing me and I'll eventually put
|
||||
it here.</para>
|
||||
<answer>
|
||||
|
||||
<para>I don't know of any, and I don't think there'll ever be one
|
||||
supporting all of <function>dlopen</function>'s options.</para>
|
||||
|
||||
<para>There are alternatives though: libtltdl (a part of libtool),
|
||||
which wraps a variety of different dynamic loading APIs, among
|
||||
others <function>dlopen</function> and
|
||||
<function>LoadLibrary</function>. Another one is the <ulink
|
||||
url="http://developer.gnome.org/doc/API/glib/glib-dynamic-loading-of-modules.html">Dynamic
|
||||
Module Loading functionality of GLib</ulink>. You can use one
|
||||
of these to ensure better possible cross-platform compatibility.
|
||||
I've never used any of them, so I can't tell you how stable they
|
||||
are and whether they really work.</para>
|
||||
|
||||
</answer>
|
||||
</qandaentry>
|
||||
</qandaset>
|
||||
</sect1>
|
||||
</section>
|
||||
|
||||
<sect1 id="seealso">
|
||||
<section id="seealso">
|
||||
<title>See Also</title>
|
||||
|
||||
<itemizedlist>
|
||||
|
@ -703,7 +725,7 @@ extern "C" void destroy(polygon* p) {
|
|||
|
||||
</itemizedlist>
|
||||
|
||||
</sect1>
|
||||
</section>
|
||||
|
||||
<bibliography>
|
||||
|
||||
|
@ -716,8 +738,8 @@ extern "C" void destroy(polygon* p) {
|
|||
|
||||
<bibliomixed>
|
||||
<abbrev>STR2000</abbrev>
|
||||
<author><surname>Stroustrup</surname>,
|
||||
<firstname>Bjarne</firstname>.</author>
|
||||
<author><surname>Stroustrup</surname>
|
||||
<firstname>Bjarne</firstname></author>
|
||||
<title>The C++ Programming Language</title>, <edition>Special
|
||||
Edition</edition>.
|
||||
ISBN <isbn>0-201-70073-5</isbn>.
|
||||
|
@ -728,6 +750,3 @@ extern "C" void destroy(polygon* p) {
|
|||
|
||||
</article>
|
||||
|
||||
|
||||
<!-- LocalWords: dlopen
|
||||
-->
|
||||
|
|
|
@ -639,7 +639,7 @@ This HOWTO has been removed for review. </Para>
|
|||
<ULINK URL="../C++-dlopen/index.html">C++-dlopen</ULink>,
|
||||
<CiteTitle>C++ dlopen mini HOWTO</CiteTitle>
|
||||
</Para><Para>
|
||||
<CiteTitle>Updated: December 2002</CiteTitle>.
|
||||
<CiteTitle>Updated: August 2003</CiteTitle>.
|
||||
How to dynamically load C++ functions and classes using
|
||||
the dlopen API. </Para>
|
||||
</ListItem>
|
||||
|
|
|
@ -242,7 +242,7 @@ and dynamically loaded libraries. </Para>
|
|||
<ULINK URL="../C++-dlopen/index.html">C++-dlopen</ULink>,
|
||||
<CiteTitle>C++ dlopen mini HOWTO</CiteTitle>
|
||||
</Para><Para>
|
||||
<CiteTitle>Updated: December 2002</CiteTitle>.
|
||||
<CiteTitle>Updated: August 2003</CiteTitle>.
|
||||
How to dynamically load C++ functions and classes using
|
||||
the dlopen API. </Para>
|
||||
</ListItem>
|
||||
|
|
Loading…
Reference in New Issue