views:

432

answers:

4

Hi,

I'm working on my first XPCOM component. Unfortunately, I can't register it successfully.

Building is ok. Here's the makefile

CXX   = g++
CPPFLAGS +=     -fno-rtti \
      -fexceptions \
      -shared \
                -fshort-wchar

# Change this to point at your Gecko SDK directory.
GECKO_SDK_PATH = /path/to/gecko/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 ${GECKO_SDK_PATH}/include/xpcom/xpcom-config.h

GECKO_DEFINES  = -DXPCOM_GLUE -DXPCOM_GLUE_USE_NSPR

GECKO_INCLUDES = -I ${GECKO_SDK_PATH}/sdk/include \
                 -I ${GECKO_SDK_PATH}/include/necko \
                 -I ${GECKO_SDK_PATH}/include/nss \
                 -I ${GECKO_SDK_PATH}/include/nspr

GECKO_LDFLAGS =  -L${GECKO_SDK_PATH}/lib -L${GECKO_SDK_PATH}/bin -Wl,-rpath-link,${GECKO_SDK_PATH}/bin -lxpcomglue_s -lxpcom -lnspr4     

FILES = Component.cpp ComponentModule.cpp

TARGET = Component.so

build:
   $(CXX) -Wall -Os -o $(TARGET) $(GECKO_CONFIG_INCLUDE) $(GECKO_DEFINES) $(GECKO_INCLUDES) $(GECKO_LDFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(FILES)
   chmod +x $(TARGET)
   strip $(TARGET)

clean:
   rm $(TARGET)

I created a new extension folder under my development firefox profile's extension directory. The IComponent.xpt and Component.so files are placed there under the component directory.

I then removed the compreg.dat and xpti.dat from my development firefox profile. I restarted it, which should automatically register the components. But the XPCOM viewer didn't show my component.

I ran this command to check for errors

./run-mozilla.sh `which ldd` -r /path/to/component/Component.so

It showed me several undefined symbols

...
undefined symbol: _ZNK9nsAString12BeginReadingEv   (/path/to/component/Component.so)
undefined symbol: _ZNK10nsACString12BeginReadingEv   (/path/to/component/Component.so)
undefined symbol: _ZN9nsAString17DefaultComparatorEPKtS1_j   (/path/to/component/Component.so)
undefined symbol: _ZNK9nsAString6EqualsEPKtPFiS1_S1_jE   (/path/to/component/Component.so)
undefined symbol: _ZN9nsAString13AssignLiteralEPKc   (/path/to/component/Component.so)
undefined symbol: _ZN13nsCOMPtr_base16begin_assignmentEv   (/path/to/component/Component.so)
undefined symbol: _ZN13nsCOMPtr_baseD2Ev   (/path/to/component/Component.so)
undefined symbol: _Z16NS_TableDrivenQIPvPK12QITableEntryRK4nsIDPS_   (/path/to/component/Component.so)
undefined symbol: _Z20NS_NewGenericModule2PK12nsModuleInfoPP9nsIModule   (/path/to/component/Component.so)

I've been using nsAString and COMPtr in my code.

Are there anything wrong with my steps? Can anyone explain why are there undefined symbols? What do undefined symbols mean? How do you get them recognised? Thanks!

Zan

A: 

Have you tried to remove -fshort-wchar compiler option?

Mladen Jankovic
+1  A: 

Actually I switched to javascript for writing XPCOM. It's much easier! I'll make a blog post on writing javascript XPCOM soon

liangzan
+1  A: 

You've apparently seen this, but for the reference: https://developer.mozilla.org/en/Troubleshooting_XPCOM_components_registration

As for your problem, I'm not an expert, but you seem to have failed to use XPCOM Glue properly. The documentation says you don't need to define XPCOM_GLUE when building a component. (If that doesn't help, you should post to mozilla forums (e.g. mozilla.dev.extensions or xpcom), where the real gurus are likely to see your question, since as you can see few people are well-versed with the build/registration machinery.)

+1 on using JS components, by the way!

Nickolay
A: 

In my case, it helped to move the $(GECKO_LDFLAGS) variable to the end, i.e. replacing:

$(CXX) -Wall -Os -o $(TARGET) $(GECKO_CONFIG_INCLUDE) $(GECKO_DEFINES) $(GECKO_INCLUDES) $(GECKO_LDFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(FILES)

with

$(CXX) -Wall -Os -o $(TARGET) $(GECKO_CONFIG_INCLUDE) $(GECKO_DEFINES) $(GECKO_INCLUDES)  $(CPPFLAGS) $(CXXFLAGS) $(FILES) $(GECKO_LDFLAGS)

after reading:

Linux and Mac: Make sure the Gecko libraries are listed after your object (.o) files on the link line.

on this page that gives instructions on XPCOM Linking:

Abrax5