Building a component DLL

Here is an example for building an XPCOM component library. In this example, all of the source files are in the same directory.

DEPTH           = ../../../..
topsrcdir       = @top_srcdir@
srcdir          = @srcdir@
VPATH           = @srcdir@

include $(DEPTH)/config/

MODULE         = filepicker
LIBRARY_NAME   = fileview
SHORT_LIBNAME  = fileview
MODULE_NAME    = nsFileViewModule
  xpcom \
  layout \
  dom \
  string \
  locale \

  nsFileView.cpp \
  nsWildCard.cpp \


include $(topsrcdir)/config/

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 are extra libraries and linker flags necessary for building components. Components using the external API have $(XPCOM_GLUE_LDOPTS) added to it. Use this for FORCE_SHARED_LIB. Core Mozilla libs, which are part of libxul and use the internal API, use $(XPCOM_LDOPTS) instead.

Document Tags and Contributors

Contributors to this page: gps, Editmonkey, BenB, Nickolay, BenjaminSmedberg
Last updated by: gps,