Building a component DLL

  • Revision slug: Building_a_component_DLL
  • Revision title: Building a component DLL
  • Revision id: 61215
  • Created:
  • Creator: BenB
  • Is current revision? No
  • Comment FORCE_SHARED_LIB; 37 words added, 4 words removed

Revision Content

Here is an example Makefile.in for building an XPCOM component library. In this example, all of the source files are in the same directory. {{ :en/Standard_Makefile_Header() }}

MODULE         = filepicker
LIBRARY_NAME   = fileview
SHORT_LIBNAME  = fileview
FORCE_SHARED_LIB = 1 or EXPORT_LIBRARY = 1
IS_COMPONENT   = 1
MODULE_NAME    = nsFileViewModule
REQUIRES = \
  xpcom \
  layout \
  dom \
  string \
  locale \
  $(NULL)

CPPSRCS = \
  nsFileView.cpp \
  nsWildCard.cpp \
  $(NULL)

include $(DEPTH)/config/autoconf.mk

EXTRA_DSO_LDOPTS += $(XPCOM_GLUE_LDOPTS)

There are several variables involved here:

  • MODULE should be set to a short name for this module of code.
  • LIBRARY_NAME should be set to the base name of the shared library that should be created for this module. You should not prepend "lib" or append any suffix such as "dll" to this name.
    If LIBRARY_NAME is longer than 8 characters, you should set SHORT_LIBNAME to an 8 character or less name for this library. This is to address limitations on Windows and OS/2. If LIBRARY_NAME is 8 characters or less, you do not need to specify SHORT_LIBNAME.
  • EXPORT_LIBRARY should be set to 1 unless FORCE_SHARED_LIB is set.
  • FORCE_SHARED_LIB should be set to 1, if your module is a shared library (.dll) even in a static build (libxul). Normally, that's what you want for libraries that are not part of core Mozilla.
  • IS_COMPONENT should be set to 1 for all components.
  • MODULE_NAME is used mainly for static builds, and should match the module name used in your NS_IMPL_NSGETMODULE call.
  • REQUIRES is a list of other modules whose header files you need to include. dist/include/module_name is added to the compiler include list for each module you specify in REQUIRES.
  • CPPSRCS lists the C++ files to compile in this directory. You can use CSRCS to specify C files.
  • EXTRA_DSO_LDOPTS has $(XPCOM_GLUE_LDOPTS) added to it. These are extra libraries and linker flags necessary for building components.

Revision Source

<p>Here is an example <code>Makefile.in</code> for building an XPCOM component library. In this example, all of the source files are in the same directory. {{ :en/Standard_Makefile_Header() }}</p>
<pre class="eval"><a href="/en/MODULE" title="en/MODULE">MODULE</a>         = filepicker
<a href="/en/LIBRARY_NAME" title="en/LIBRARY_NAME">LIBRARY_NAME</a>   = fileview
<a href="/en/SHORT_LIBNAME" title="en/SHORT_LIBNAME">SHORT_LIBNAME</a>  = fileview
<code><a href="/en/FORCE_SHARED_LIB" title="FORCE_SHARED_LIB">FORCE_SHARED_LIB</a> = 1</code> or <a href="/en/EXPORT_LIBRARY" title="en/EXPORT_LIBRARY">EXPORT_LIBRARY</a> = 1
<a href="/en/IS_COMPONENT" title="en/IS_COMPONENT">IS_COMPONENT</a>   = 1
<a href="/en/MODULE_NAME" title="en/MODULE_NAME">MODULE_NAME</a>    = nsFileViewModule
<a href="/en/REQUIRES" title="en/REQUIRES">REQUIRES</a> = \
  xpcom \
  layout \
  dom \
  string \
  locale \
  $(NULL)

<a href="/en/CPPSRCS" title="en/CPPSRCS">CPPSRCS</a> = \
  nsFileView.cpp \
  nsWildCard.cpp \
  $(NULL)

include $(DEPTH)/config/autoconf.mk

<a href="/en/EXTRA_DSO_LDOPTS" title="en/EXTRA_DSO_LDOPTS">EXTRA_DSO_LDOPTS</a> += $(<a href="/en/MOZ_COMPONENT_LIBS" title="en/MOZ_COMPONENT_LIBS">XPCOM_GLUE_LDOPTS</a>)
</pre>
<p>There are several variables involved here:</p>
<ul> <li><strong>MODULE</strong> should be set to a short name for this module of code.</li> <li><strong>LIBRARY_NAME</strong> should be set to the base name of the shared library that should be created for this module. You should not prepend "lib" or append any suffix such as "dll" to this name.<br> If <code>LIBRARY_NAME</code> is longer than 8 characters, you should set <strong>SHORT_LIBNAME</strong> to an 8 character or less name for this library. This is to address limitations on Windows and OS/2. If <code>LIBRARY_NAME</code> is 8 characters or less, you do not need to specify <code>SHORT_LIBNAME</code>.</li> <li><strong>EXPORT_LIBRARY</strong> should be set to 1 unless <strong>FORCE_SHARED_LIB</strong> is set.</li> <li><strong>FORCE_SHARED_LIB</strong> should be set to 1, if your module is a shared library (.dll) even in a static build (libxul). Normally, that's what you want for libraries that are not part of core Mozilla.</li> <li><strong>IS_COMPONENT</strong> should be set to 1 for all components.</li> <li><strong>MODULE_NAME</strong> is used mainly for static builds, and should match the module name used in your <code>NS_IMPL_NSGETMODULE</code> call.</li> <li><strong>REQUIRES</strong> is a list of other modules whose header files you need to include. <code>dist/include/module_name</code> is added to the compiler include list for each module you specify in REQUIRES.</li> <li><strong>CPPSRCS</strong> lists the C++ files to compile in this directory. You can use <strong>CSRCS</strong> to specify C files.</li> <li><strong>EXTRA_DSO_LDOPTS</strong> has <code>$(</code>XPCOM_GLUE_LDOPTS<code>)</code> added to it. These are extra libraries and linker flags necessary for building components.</li>
</ul>
Revert to this revision