我正在尝试在LINUX操作系统下为Firefox 3.6.13构建简单的XPCOM组件。我使用Xulrunner SDK 1.9.2.13成功编译了该组件。我将它保存在组件目录下。但是,当我启动我的firefox firefox控制台显示错误
'无法加载XPCOM组件: /home/mypc/.mozilla/firefox/cxsm79p6.default/extensions/ {1280606b-2510-4fe0-97ef-9b5a22eafe80} /components/MyComponent.so
通过引用此链接https://developer.mozilla.org/en/Troubleshooting_XPCOM_components_registration,我按照“Linux特定提示”标题下的说明进行操作。它表示在链接时使用特殊链接时间选项-Wl,-z,defs
。所以我添加了这些选项,但现在将其显示错误编译为
make: Warning: File `Makefile' has modification time 0.25 s in the future
c ++ -Os -Wall -o MyComponent.so -include xpcom-config.h -DXPCOM_GLUE_USE_NSPR -I / mnt / hgfs / C / Users / sunil / SDKS / LINUX / xulrunner-sdk / include -I./ -L / mnt / hgfs / C / Users / sunil / SDKS / LINUX / xulrunner-sdk / lib -lxpcomglue_s -lxpcom -lnspr4 -fno-rtti -fno-exceptions -shared -Wl,-z,defs MyComponent.cpp MyComponentModule.cpp /tmp/ccMGUTql.o:在函数中
MyComponent::QueryInterface(nsID const&, void**)': MyComponent.cpp:(.text+0x9b): undefined reference to
NS_TableDrivenQI(void *,QITableEntry const *,nsID const&,void **)' /tmp/ccbkZLTz.o:在功能上NSGetModule': MyComponentModule.cpp:(.text+0x15): undefined reference to
NS_NewGenericModule2(nsModuleInfo const *,nsIModule * )'collect2:ld 返回1退出状态make:* * [build]错误1
我的新makefile如下
CXX = c++
CPPFLAGS += -fno-rtti \
-fno-exceptions \
-shared \
-Wl,-z,defs
# Change this to point at your Gecko SDK directory.
GECKO_SDK_PATH =/mnt/hgfs/C/Users/sunil/SDKS/LINUX/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 = -DXPCOM_GLUE_USE_NSPR
GECKO_INCLUDES = -I $(GECKO_SDK_PATH)/include
GECKO_LDFLAGS = -L $(GECKO_SDK_PATH)/lib -lxpcomglue_s -lxpcom \
-lnspr4
FILES = MyComponent.cpp MyComponentModule.cpp
TARGET = MyComponent.so
build:
$(CXX) -Os -Wall -o $(TARGET) $(GECKO_CONFIG_INCLUDE) $(GECKO_DEFINES) $(GECKO_INCLUDES) -I./ $(GECKO_LDFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(FILES)
chmod +x $(TARGET)
strip $(TARGET)
clean:
rm $(TARGET)
有人可以帮助我解决这个问题吗?
答案 0 :(得分:0)
如果您的库未指定correctly,我认为您会收到此错误。其中一条线可能会解决它:
GECKO_LDFLAGS = -L$(GECKO_SDK_PATH)/lib -L$(GECKO_SDK_PATH)/bin -Wl,-rpath-link,$(GECKO_SDK_PATH)/bin -lxpcomglue_s -lxpcom -lnspr4
或
$(CXX) -Os -Wall -o $(TARGET) $(GECKO_CONFIG_INCLUDE) $(GECKO_DEFINES) $(GECKO_INCLUDES) -I./ $(CPPFLAGS) $(CXXFLAGS) $(FILES) $(GECKO_LDFLAGS)