1

I've tried the advice on threads here and here to no avail.

I have Xcode 5.0.2 installed and I am compiling everything on the command line. After make/make install to build libjson, I created a simple test file to link and build from it:

#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;
}

When I try to build this file:

g++ -DNDEBUG main.cpp -ljson

I get this:

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));
4

1 回答 1

0

在我意识到制作过程有问题后,从另一个SO 问题中找到了答案。基本上,解决方案是将源代码复制到 Xcode 中并将其构建为项目的一部分,而不是尝试将其链接为库。

我还尝试在 ubuntu 机器(12.04)上构建 libjson 7.6.1,尽管制作完美,但遇到了确切的问题。

于 2013-12-22T22:12:56.620 回答