对YAML :: LoadFile的未定义引用 [英] undefined reference to YAML::LoadFile

查看:374
本文介绍了对YAML :: LoadFile的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用新版本的libyaml-cpp并出现链接器问题(undefined reference to 'YAML::LoadFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)').

I'm trying to use the new version of libyaml-cpp and having linker problems (undefined reference to 'YAML::LoadFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)').

我按如下方式构建该库:

I build the library as follows:

cmake -DBUILD_SHARED_LIBS=ON ..
make
sudo make install

然后我包含yaml-cpp/yaml.h并致电YAML::LoadFile( some_string );.我的编译行是:

Then I include yaml-cpp/yaml.h and call YAML::LoadFile( some_string );. My compilation line is:

g++ -L/usr/local/lib -I/usr/local/include -lyaml-cpp -std=c++0x -o $@  $^

我也尝试将确切的.so文件放入其中,但是没有运气.使用nm,我可以在共享库中看到一个LoadFile函数.我现在不知道是由于某种原因使用了错误的构建线,还是库有问题.

I've tried putting the exact .so file in there as well with no luck. Using nm I can see a LoadFile function in the shared library. I can't figure out now if I'm somehow using the wrong build line or there is something wrong with the library.

推荐答案

这是命令行上的排序问题.我想我永远也不会理解GCC命令行逻辑.只需将库放在末尾就可以了:

It's an ordering problem on the command-line. I guess I'll just never understand GCC command-line logic. Simply putting the library at the end seems to work:

g++ -L/usr/local/lib -I/usr/local/include -std=c++0x -o $@  $^ -lyaml-cpp

这篇关于对YAML :: LoadFile的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆