[英]Why does ctime clock() give different times when called twice by same program for same operation?
[英]Why does TinyXPath give different results for the same object when called in two different classes?
我正在Ubuntu上構建一個項目,我正在使用TinyXPath庫和TinyXml來解析以下xml:
<nodes>
<node attribute1="1" attribute2="2" />
<node attribute1="2" attribute2="3" />
...
<node attribute1="10" attribute2="11" />
</nodes>
要找出包含的節點條目數,我正在使用:
TinyXPath::i_xpath_int( xml_root,"count(/nodes/node)")
顯然,在一個對象中使用此函數調用返回實際的節點數,10; 但是在另一個對象(一個不同的類類型)中使用它,它總是返回0.我檢查過兩個情況下xml_root是否是同一個對象,並且兩個對象具有相同的地址。 打印內容給了我相同的xml。
相反,如果我使用TinyXML,我會得到正確的結果,我甚至可以訪問所有的屬性並獲得正確的結果。 以下代碼給出了正確的no_nodes:
for(node = xml_root->FirstChild(); node; node = node->NextSibling())
no_nodes++;
這是奇怪的部分。 如果我在Windows 7上構建這個項目,它的工作正常。 函數調用始終返回正確數量的節點。 以前有人遇到過這種問題嗎?
PS:我知道我沒有就這個問題給出很多具體細節,但這是一個龐大的項目,我需要幾天的時間來解釋這一切。 所以這只是在黑暗中拍攝的。
通過使用gdb,我發現“count(/ products / product)”沒有解析問題,正如我最初想的那樣。
問題是我的項目使用了很多不同的庫。 其中一個庫使用了tinyxpath使用的tinyxml的不同版本。
當我從我的項目鏈接該類的二進制文件時,其中tinyxpath不起作用,我在我的makefile中使用了以下命令:
g++ -o binary -lahttplib -ltinyxpath [...]
ahttplib已經包含了舊版本的tinyxml。 因此,當鏈接tinyxpath時,它鏈接到已經包含在ahttplib中的tinyxml庫,而不是它自己的版本。 來自ahttplib的tinyxml版本和來自tinyxpath的版本是不兼容的。
我的項目中的類的二進制文件,其中tinyxpath正常工作只包括tinyxpath,所以問題沒有發生在那里。
簡單的解決方案是更改鏈接順序:ahttplib之前的tinxypath。 解決這個問題的正確方法是使ahttplib和tinyxpath引用相同的tinyxml庫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.