I'm having some difficulty getting an XPCOM component to load into
firefox using the xulrunner 1.9 SDK on Mac OS X. (I'm not building
from the firefox source tree.) When Firefox tries to load my
component, I get the following error message in the Javascript
console:
"Failed to load XPCOM component: <my extension path>/components/
MyComponent.dylib"
Enabling NSPR tracing as suggested on the Mozilla Wiki gives me the
following error:
"1609119968[40aab0]: nsNativeModuleLoader::LoadModule("<extension
path>/components/MyComponent.dylib") - load FAILED, rv: 80004005,
error:
Unknown error: -2804"
I'm using a Makefile to build my component. After building, I copy the
library to the components folder of my extension, delete compreg.dat
and restart Firefox. That's when I get the error message.
I'm running this on Leopard with Firefox 3.5.5. I've also tried it
with the latest nightly with the same result.
I'm using the following Makefile, although I've tried many variations
of build and linker flags according to advice on forums and mailing
lists. There doesn't seem to be any example of a recent OS X Makefile
anywhere online, so it's possible that I'm just not including the
correct linker flags.
CXX = c++
CPPFLAGS += -fno-rtti \
-fno-exceptions \
-fshort-wchar \
-fPIC \
-fno-common
# Change this to point at your Gecko SDK directory.
GECKO_SDK_PATH = $(HOME)/Downloads/xulrunner-sdk
# GCC only define which allows us to not have to #include mozilla-
config
# in every .cpp file. If your not using GCC remove this line and add
# #include "mozilla-config.h" to each of your .cpp files.
GECKO_CONFIG_INCLUDE = -include xpcom-config.h
GECKO_DEFINES = -DXP_UNIX -DXP_MACOSX
GECKO_INCLUDES = -I $(GECKO_SDK_PATH)/sdk/include -I../
EncryptionServer
GECKO_LDFLAGS = -L$(GECKO_SDK_PATH)/sdk/lib \
-L$(GECKO_SDK_PATH)/bin \
-Wl,-executable_path,$(GECKO_SDK_PATH)/bin \
-lxpcomglue_s \
-lxpcom \
-lnspr4
FILES = MyComponent.cpp MyComponentModule.cpp CryptoUtils.cpp
TARGET = MyComponent.dylib
build:
$(CXX) -dynamiclib -Wall -Os -o $(TARGET) $(GECKO_CONFIG_INCLUDE) $
(GECKO_DEFINES) $(GECKO_INCLUDES) $(FILES) $(GECKO_LDFLAGS) $
(CPPFLAGS) $(CXXFLAGS) -framework CoreFoundation -framework XUL -
framework Carbon
chmod +x $(TARGET)
strip $(TARGET)
clean:
rm $(TARGET)
I'm at my wits end on this one. It would be nice if I could get this
to work, as I'm planning on putting up a guide on how to build Mac OS
X XPCOM components to spare others the same pain.
Thanks,
Sam
> build:
> $(CXX) -dynamiclib -Wall -Os -o $(TARGET) $(GECKO_CONFIG_INCLUDE) $
> (GECKO_DEFINES) $(GECKO_INCLUDES) $(FILES) $(GECKO_LDFLAGS) $
> (CPPFLAGS) $(CXXFLAGS) -framework CoreFoundation -framework XUL -
> framework Carbon
It looks like you're trying to compile a true .dylib, whereas I'm pretty
sure that XPCOM components need to be bundle libraries instead so that they
can be dynamically loaded. For instance, here's the command which links one
of the Firefox binary components:
g++-4.2 -arch i386 -fno-rtti -fno-exceptions -Wall -Wpointer-arith
-Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor
-Wcast-align -Wno-invalid-offsetof -Wno-variadic-macros -Wno-long-long
-gdwarf-2 -isysroot /Developer/SDKs/MacOSX10.5.sdk -fno-strict-aliasing
-fpascal-strings -fno-common -fshort-wchar -pthread -DNO_X11 -DNDEBUG
-DTRIMMED -O3 -fPIC -o libbrowsercomps.dylib nsModule.o nsFeedSniffer.o
nsPlacesImportExportService.o nsPrivateBrowsingServiceWrapper.o
AboutRedirector.o DirectoryProvider.o nsMacShellService.o
nsProfileMigrator.o nsBrowserProfileMigratorUtils.o
nsNetscapeProfileMigratorBase.o nsSeamonkeyProfileMigrator.o
nsPhoenixProfileMigrator.o nsDogbertProfileMigrator.o
nsOperaProfileMigrator.o nsSafariProfileMigrator.o nsMacIEProfileMigrator.o
nsOmniWebProfileMigrator.o nsCaminoProfileMigrator.o nsICabProfileMigrator.o
-framework Cocoa
-Wl,-executable_path,/builds/moz2_slave/mozilla-central-macosx-nightly/build/obj-firefox/i386/dist/bin
-Wl,-dead_strip
-L/builds/moz2_slave/mozilla-central-macosx-nightly/build/obj-firefox/i386/dist/lib
-lunicharutil_external_s
/builds/moz2_slave/mozilla-central-macosx-nightly/build/obj-firefox/i386/dist/lib/libmozreg_s.a
/builds/moz2_slave/mozilla-central-macosx-nightly/build/obj-firefox/i386/dist/lib/libxpcomglue_s.a
-L/builds/moz2_slave/mozilla-central-macosx-nightly/build/obj-firefox/i386/dist/bin
-lxpcom
/builds/moz2_slave/mozilla-central-macosx-nightly/build/obj-firefox/i386/dist/bin/XUL
-lobjc
-L/builds/moz2_slave/mozilla-central-macosx-nightly/build/obj-firefox/i386/dist/bin
-L/builds/moz2_slave/mozilla-central-macosx-nightly/build/obj-firefox/i386/dist/lib
-lplds4 -lplc4 -lnspr4 -framework Carbon -framework CoreAudio -framework
AudioToolbox -framework AudioUnit -framework AddressBook
-Wl,-exported_symbols_list
-Wl,/builds/moz2_slave/mozilla-central-macosx-nightly/build/build/unix/gnu-ld-scripts/components-export-list
-bundle
If you use -bundle I think you'll have better results.
--BDS
Thanks, I think that fixed it. (I'm still having other problems, but I
think they're unrelated.)
> --BDS