2012-01-15 66 views
3

我試圖建立可以在這裏XPCOM組件: http://mxr.mozilla.org/mozilla-central/source/xpcom/sample/構建XPCOM Mozilla的樣品組分

我想用我自己的Makefile來編譯它,所以這個組件可以從Mozilla的全部來源中分離。

因此,這裏是我的文件樹:

[email protected] /cygdrive/c/dev/central_sample 
$ ls -Rlah 
.: 
total 57K 
d---------+ 1 frinux None 0 Jan 15 21:28 . 
d---------+ 1 frinux None 0 Jan 15 20:34 .. 
----------+ 1 frinux None 989 Jan 15 21:22 Makefile 
----------+ 1 frinux None 2.4K Jan 15 21:05 nsISample.idl 
----------+ 1 frinux None 6.0K Jan 15 21:05 nsSample.cpp 
----------+ 1 frinux None 5.1K Jan 15 21:06 nsSample.h 
----------+ 1 frinux None 2.0K Jan 15 21:06 nsSample.js 
----------+ 1 frinux None 131 Jan 15 21:06 nsSample.manifest 
----------+ 1 frinux None 4.7K Jan 15 21:06 nsSampleModule.cpp 
d---------+ 1 frinux None 0 Jan 15 21:28 program 
----------+ 1 frinux None 8.7K Jan 15 21:06 xpconnect-sample.html 

./program: 
total 16K 
d---------+ 1 frinux None 0 Jan 15 21:28 . 
d---------+ 1 frinux None 0 Jan 15 21:28 .. 
----------+ 1 frinux None 2.7K Jan 15 21:07 Makefile.in 
----------+ 1 frinux None 4.5K Jan 15 21:07 nsTestSample.cpp 

這裏是我做出的生成文件:我想在Windows下用Cygwin來構建它

CXX = c++ 
CPPFLAGS +=  -fno-rtti    \ 
     -fno-exceptions  \ 
     -shared 

# Change this to point at your Gecko SDK directory. 
GECKO_SDK_PATH = /cygdrive/c/dev/greenchallenge/xulrunner-sdk-9.0.1 

# 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 mozilla-config.h 

GECKO_DEFINES = -DXPCOM_GLUE -DXP_WIN 

GECKO_INCLUDES = -I $(GECKO_SDK_PATH)/include 

GECKO_LDFLAGS = -L $(GECKO_SDK_PATH)/lib -lxpcomglue \ 
       -lnspr4  \ 
       -lplds4  

FILES = nsSample.cpp nsSampleModule.cpp 

TARGET = sample.dll 

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) 

(用gcc & G ++安裝) 。

編譯時,我得到茨艾倫錯誤,以及研究一些小時後,我還是不明白他們:

$ make 
c++ -Wall -Os -o greenfox.dll -include mozilla-config.h -DXPCOM_GLUE -DXP_WIN -I /cygdrive/c/dev/greenchallenge/xulrunner-sdk-9.0.1/include -L /cygdrive/c/dev/greenchallenge/xulrunner-sdk-9.0.1/lib -lxpcomglue -lnspr4  -lplds4  -fno-rtti    -fno-exceptions   -shared nsSample.cpp nsSampleModule.cpp 
In file included from nsSample.cpp:48: 
nsSample.h:44:23: nsISample.h: No such file or directory 
In file included from nsSample.cpp:48: 
nsSample.h:64: error: expected class-name before '{' token 
nsSample.h:76: error: `NS_DECL_ISUPPORTS' does not name a type 
In file included from /cygdrive/c/dev/greenchallenge/xulrunner-sdk-9.0.1/include/nsAlgorithm.h:43, 
       from /cygdrive/c/dev/greenchallenge/xulrunner-sdk-9.0.1/include/nsTArray.h:45, 
       from /cygdrive/c/dev/greenchallenge/xulrunner-sdk-9.0.1/include/nsStringAPI.h:56, 
       from /cygdrive/c/dev/greenchallenge/xulrunner-sdk-9.0.1/include/nsEmbedString.h:43, 
       from nsSample.cpp:51: 
/cygdrive/c/dev/greenchallenge/xulrunner-sdk-9.0.1/include/nsCharTraits.h:143: error: an explicit specialization must be preceded by 'template <>' 
/cygdrive/c/dev/greenchallenge/xulrunner-sdk-9.0.1/include/nsCharTraits.h:433: error: an explicit specialization must be preceded by 'template <>' 
/cygdrive/c/dev/greenchallenge/xulrunner-sdk-9.0.1/include/nsCharTraits.h:727: error: an explicit specialization must be preceded by 'template <>' 
/cygdrive/c/dev/greenchallenge/xulrunner-sdk-9.0.1/include/nsCharTraits.h:763: error: an explicit specialization must be preceded by 'template <>' 
/cygdrive/c/dev/greenchallenge/xulrunner-sdk-9.0.1/include/nsCharTraits.h:828: error: an explicit specialization must be preceded by 'template <>' 
/cygdrive/c/dev/greenchallenge/xulrunner-sdk-9.0.1/include/nsCharTraits.h:840: error: an explicit specialization must be preceded by 'template <>' 
nsSample.cpp:61: error: no `nsSampleImpl::~nsSampleImpl()' member function declared in class `nsSampleImpl' 
nsSample.cpp:81: error: no `nsrefcnt nsSampleImpl::AddRef()' member function declared in class `nsSampleImpl' 
nsSample.cpp: In member function `nsrefcnt nsSampleImpl::AddRef()': 
nsSample.cpp:81: error: `mRefCnt' undeclared (first use this function) 
nsSample.cpp:81: error: (Each undeclared identifier is reported only once for each function it appears in.) 
nsSample.cpp: At global scope: 
nsSample.cpp:81: error: no `nsrefcnt nsSampleImpl::Release()' member function declared in class `nsSampleImpl' 
nsSample.cpp: In member function `nsrefcnt nsSampleImpl::Release()': 
nsSample.cpp:81: error: `mRefCnt' undeclared (first use this function) 
nsSample.cpp: At global scope: 
nsSample.cpp:81: error: no `nsresult nsSampleImpl::QueryInterface(const nsIID&, void**)' member function declared in class `nsSampleImpl' 
nsSample.cpp: In member function `nsresult nsSampleImpl::QueryInterface(const nsIID&, void**)': 
nsSample.cpp:81: error: `::nsISample' has not been declared 
nsSample.cpp:81: error: `COMTypeInfo' undeclared (first use this function) 
nsSample.cpp:81: error: expected primary-expression before "int" 
nsSample.cpp:81: error: expected `)' before "int" 
nsSample.cpp:81: error: expected `)' before ';' token 
nsSample.cpp:81: error: `nsISample' has not been declared 
nsSample.cpp:81: error: expected `>' before '*' token 
nsSample.cpp:81: error: expected `(' before '*' token 
nsSample.cpp:81: error: expected primary-expression before '>' token 
nsSample.cpp:81: error: expected `)' before ';' token 
nsSample.cpp: In function `nsresult nsSampleImpl_GetInterfacesHelper(PRUint32*, nsIID***)': 
nsSample.cpp:81: error: `::nsISample' has not been declared 
nsSample.cpp:81: error: `COMTypeInfo' undeclared (first use this function) 
nsSample.cpp:81: error: expected primary-expression before '*' token 
nsSample.cpp:81: error: expected primary-expression before ')' token 
nsSample.cpp:81: error: expected `;' 
nsSample.cpp: At global scope: 
nsSample.cpp:89: error: no `nsresult nsSampleImpl::GetValue(char**)' member function declared in class `nsSampleImpl' 
nsSample.cpp:120: error: no `nsresult nsSampleImpl::SetValue(const char*)' member function declared in class `nsSampleImpl' 
nsSample.cpp:141: error: no `nsresult nsSampleImpl::Poke(const char*)' member function declared in class `nsSampleImpl' 
nsSample.cpp: In member function `nsresult nsSampleImpl::Poke(const char*)': 
nsSample.cpp:142: error: `SetValue' undeclared (first use this function) 
nsSample.cpp: At global scope: 
nsSample.cpp:153: error: no `nsresult nsSampleImpl::WriteValue(const char*)' member function declared in class `nsSampleImpl' 
In file included from /cygdrive/c/dev/greenchallenge/xulrunner-sdk-9.0.1/include/mozilla/Module.h:44, 
       from /cygdrive/c/dev/greenchallenge/xulrunner-sdk-9.0.1/include/mozilla/ModuleUtils.h:42, 
       from nsSampleModule.cpp:39: 
/cygdrive/c/dev/greenchallenge/xulrunner-sdk-9.0.1/include/nsCOMPtr.h:895: error: an explicit specialization must be preceded by 'template <>' 
/cygdrive/c/dev/greenchallenge/xulrunner-sdk-9.0.1/include/nsCOMPtr.h:1366: error: an explicit specialization must be preceded by 'template <>' 
In file included from nsSampleModule.cpp:42: 
nsSample.h:44:23: nsISample.h: No such file or directory 
In file included from nsSampleModule.cpp:42: 
nsSample.h:64: error: expected class-name before '{' token 
nsSample.h:125: error: ISO C++ forbids declaration of `NS_DECL_NSISAMPLE' with no type 
nsSample.h:125: error: expected `;' before "private" 
Makefile:27: recipe for target `build' failed 
make: *** [build] Error 1 

這是因爲如果有一個在Mozilla的代碼中的錯誤?我究竟做錯了什麼 ?

謝謝!

回答

1

弗拉基米爾是正確的一點:nsISample。彙編中缺少h。

但是,創建此文件不會解決主要問題:無法使用GCC for Windows編譯Mozilla XPCOM!

VisualC++ express下的相同代碼將被編譯。

這很奇怪,我不知道他們爲什麼選擇這個編譯器。不要像我一樣,不要嘗試GCC來編譯Mozilla XPCOM!

+0

你用什麼版本的Gecko SDK來構建?我正在嘗試使用MSVS 2013中的'xulrunner-34.0.5.en-US.win32.sdk'(沒有makefile),它不會構建,無論如何。 – user2173353 2014-12-04 16:42:19

2

重要的錯誤似乎是這一個,其餘的看起來像後續的錯誤:

nsSample.h:44:23:nsISample.h:沒有這樣的文件或目錄

該文件需要在編譯時被創建從nsISample.idl使用xpidl command line tool

XPIDL -m頭nsISample.idl

顯然,在新的XULRunner SDK版本你可以使用pyxpidl代替:

header.py -o nsISample.h nsISample.idl

+0

確保您使用-I開關從sdk設置idl-dir,例如:header.py -Ic:\ workspace \ xulrunner-sdk \ idl -o「nsISample.h」nsISample.idl' – weberph 2012-01-17 12:56:46