2

yaml-cpp ライブラリを使用していくつかの YAML 文字列を読みたいと思います。そのために、次の C++ コードをコンパイルしてみます。

#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <openssl/sha.h>
#include <yaml-cpp/yaml.h>

int main(){
    std::string yamlstr = "name: Test\ndescription: Test2";

    std::stringstream is(yamlstr);
    YAML::Parser parser(is);
    YAML::Node doc;
    parser.GetNextDocument(doc);

    return 0;
}

ただし、期待どおりに動作せず、実行時にリンカーが次のエラー メッセージをスローしますg++ $(pkg-config --cflags --libs yaml-cpp) test.cpp -o test

/tmp/ccEPCiDN.o: In function `main':
test.cpp:(.text+0x1e0): undefined reference to `YAML::Parser::Parser(std::basic_istream<char, std::char_traits<char> >&)'
test.cpp:(.text+0x1ef): undefined reference to `YAML::Node::Node()'
test.cpp:(.text+0x209): undefined reference to `YAML::Parser::GetNextDocument(YAML::Node&)'
test.cpp:(.text+0x218): undefined reference to `YAML::Node::~Node()'
test.cpp:(.text+0x227): undefined reference to `YAML::Parser::~Parser()'
test.cpp:(.text+0x403): undefined reference to `YAML::Node::~Node()'
test.cpp:(.text+0x412): undefined reference to `YAML::Parser::~Parser()'
collect2: ld returned 1 exit status

の出力pkg-config --cflags --libs yaml-cpp:

-I/usr/local/include  -L/usr/local/lib -lyaml-cpp 

の出力ls -l /usr/local/lib:

[...]
-rw-r--r-- 1 root root    843138 2012-03-01 10:38 libyaml-cpp.a
[...]

現在、バージョン 0.3.0 を使用していますが、現在のリポジトリのコピーもチェックアウトしました。

この問題を解決する方法を知っている人はいますか?

4

1 に答える 1

3

いくつかの可能性:

  1. yaml-cpp の共有ライブラリ バージョンの古いバージョンが何らかの形でライブラリ パスにある可能性はありますか?

  2. コマンドラインで最初にコンパイルしようとするとどうなりますかtest.cpp。たとえば、

    g++ test.cpp $(pkg-config --cflags --libs yaml-cpp) -o test
    

(ちなみに、これは静的リンクの問題であり、コンパイルの問題ではありません。)

于 2012-03-01T18:06:32.080 に答える