2013-12-22 50 views
1

我試過線程herehere的建議無濟於事。在OSX小牛上建立libjson

我安裝了Xcode 5.0.2,並且正在編譯命令行上的所有內容。化妝後/ make install來編譯libjson,我創建了一個簡單的測試文件,從它鏈接和構建:當我嘗試建立這個文件

#include <iostream> 
#include "libjson.h" 

int main(int argc, const char * argv[]) 
{ 

    // insert code here... 
    std::cout << "Hello, World!\n"; 
    JSONNode n(JSON_NODE); 
    n.push_back(JSONNode("RootA", "Hello World")); 
    JSONNode c(JSON_ARRAY); 
    c.set_name("ArrayOfNumbers"); 
    c.push_back(JSONNode("", 16)); 
    c.push_back(JSONNode("", 42)); 
    c.push_back(JSONNode("", 128)); 
    n.push_back(c); 
    std::string jc = n.write_formatted(); 
    std::cout << jc << std::endl; 
    return 0; 
} 

g++ -DNDEBUG main.cpp -ljson 

我得到這個:

main.cpp:17:5: error: unknown type name 'JSONNode' 
    JSONNode n(JSON_NODE); 
    ^
main.cpp:18:17: error: use of undeclared identifier 'JSONNode' 
    n.push_back(JSONNode("RootA", "Hello World")); 
       ^
main.cpp:19:5: error: unknown type name 'JSONNode' 
    JSONNode c(JSON_ARRAY); 
    ^
main.cpp:21:17: error: use of undeclared identifier 'JSONNode' 
    c.push_back(JSONNode("", 16)); 
       ^
main.cpp:22:17: error: use of undeclared identifier 'JSONNode' 
    c.push_back(JSONNode("", 42)); 
       ^
main.cpp:23:17: error: use of undeclared identifier 'JSONNode' 
    c.push_back(JSONNode("", 128)); 
+0

[創建一個libjson庫鏈接到xcode]可能的重複(http://stackoverflow.com/questions/20010975/creating-a-libjson-library-to-link-to-xcode) –

回答

0

在我意識到make過程出現問題後,從另一個SO question找到答案。基本上,解決方案是將源代碼複製到Xcode中,並將其作爲項目的一部分而不是將其作爲庫鏈接。

我也嘗試在ubuntu機器上構建libjson 7.6.1(12.04),並遇到了完美的問題。