2016-06-13 4 views
0

Jsoncppを使用してJsonメッセージを作成しようとしています。 次のように私がやった:JsonCppを使用してJsonメッセージを作成する

clients.cpp:(.text._ZN20multi_usrp_emulation7client1Ev[_ZN20multi_usrp_emulation7client1Ev ]+0x1d9): undefined reference to `Json::Value::operator=(Json::Value)' 
clients.cpp:(.text._ZN20multi_usrp_emulation7client1Ev[_ZN20multi_usrp_emulation7client1Ev ]+0x224): undefined reference to `Json::Value::operator=(Json::Value)' 
clients.cpp:(.text._ZN20multi_usrp_emulation7client1Ev[_ZN20multi_usrp_emulation7client1Ev ]+0x26c): undefined reference to `Json::Value::operator=(Json::Value)' 
collect2: error: ld returned 1 exit status 

私のコードが間違っているもの:

g++ -o clients clients.cpp -ljsoncpp -lzmq 

この種のエラーが発生します。

#include <string> 
#include <iostream> 
#include <sstream>  
#include <json/json.h> 

int main() 
{ 
    std::string Value = "5.17e9"; 
    std::string Type = "TX"; 
    std::string Parameter = "Frequency"; 

    Json::Value root; 
    root.append("Type"); 
    root.append("Parameter"); 
    root.append("Value"); 
    root["Type"] = Type; 
    root["Parameter"] = Parameter; 
    root["Value"] = Value; 

    Json::FastWriter fastwriter; 
    std::string message = fastwriter.write(root); 
    std::cout<<message<<std::endl; 

    return 0; 
} 

は、次のコマンドラインを使用してこのコードをコンパイルします?

+0

あなたがjsoncppのどのバージョンを使用していますか?おそらくそれはこの問題に関連しています:https://github.com/open-source-parsers/jsoncpp/issues/484? –

+0

バージョンの確認方法はありません。しかし、今日はgithub経由でダウンロードしました。私はあなたが添付した質問を読んだが、私はそれをよく理解しなかった。あなたは私を助けることができる? –

+0

バージョンは1.7.2 –

答えて

0

私はリンクのエラーについてはわかりませんが、コンパイラで異なる方法で処理される可能性のあるコードに問題があります。それは私のランタイムエラーです。

Json::Value root; 
root.append("Type"); // makes root into arrayValue 
root["Type"] = Type; // accesses root as an objectValue 
// triggers assert in Json::Value::resolveReference 

これは、私はそれを行う方法です。

Json::Value root; 
root["Type"] = Type; 
+0

素晴らしい!それは感謝の男を動作させる! –

関連する問題