linux cpp中如何调用c,如何在Linux上的C ++程序中使用yaml-cpp?

|

我最近决定使用yaml作为我的配置文件技术,并且正在OpenSuse 11.3上编写一个c ++ linux应用程序。

问题是,即使在成功安装cmake之后,如yaml-cpp docs页面上所示编译yaml-cpp,我仍然无法在此处编译yaml-cpp页面上的简单演示程序。

例如,当我尝试编译monster.yaml和main.cpp示例时

我的编译器在发出命令gcc main.cpp时,发出以下错误:

main.cpp:24:25:错误:“ YAML”未命名类型

main.cpp:24:35:错误:“&”令牌之前的预期unqualified-id

main.cpp:24:35:错误:“&”令牌之前的预期“)”

main.cpp:24:35:错误:“&”令牌之前的预期初始化程序

main.cpp:30:25:错误:“ YAML”未命名类型

main.cpp:30:35:错误:“&”令牌之前的预期unqualified-id

main.cpp:30:35:错误:“&”令牌之前的预期“)”

main.cpp:30:35:错误:“&”令牌之前的预期初始化程序

main.cpp:35:25:错误:“ YAML”未命名类型

main.cpp:35:35:错误:“&”令牌之前的预期unqualified-id

main.cpp:35:35:错误:“&”令牌之前的预期“)”

main.cpp:35:35:错误:“&”令牌之前的预期初始化程序

我尝试将include指令从#include \"yaml-cpp/yaml.h\"更改为#include ,因为我已经安装了yaml lib,但这并不能解决任何问题。

那我做错了什么?

这是从第24行到第40行粘贴的有问题的代码:

void operator >> (const YAML::Node& node, Vec3& v) {

node[0] >> v.x;

node[1] >> v.y;

node[2] >> v.z;

}

void operator >> (const YAML::Node& node, Power& power) {

node[\"name\"] >> power.name;

node[\"damage\"] >> power.damage;

}

void operator >> (const YAML::Node& node, Monster& monster) {

node[\"name\"] >> monster.name;

node[\"position\"] >> monster.position;

const YAML::Node& powers = node[\"powers\"];

for(unsigned i=0;i

Power power;

powers[i] >> power;

monster.powers.push_back(power);

}

}

这是我运行make命令之后的sudo make install输出的转储:

[ 81%] Built target yaml-cpp

[ 96%] Built target run-tests

[100%] Built target parse

Install the project...

-- Install configuration: \"Release\"

-- Installing: /usr/local/lib/libyaml-cpp.so.0.2.6

-- Up-to-date: /usr/local/lib/libyaml-cpp.so.0.2

-- Up-to-date: /usr/local/lib/libyaml-cpp.so

-- Up-to-date: /usr/local/include/yaml-cpp/aliasmanager.h

-- Up-to-date: /usr/local/include/yaml-cpp/anchor.h

-- Up-to-date: /usr/local/include/yaml-cpp/conversion.h

-- Up-to-date: /usr/local/include/yaml-cpp/dll.h

-- Up-to-date: /usr/local/include/yaml-cpp/emitfromevents.h

-- Up-to-date: /usr/local/include/yaml-cpp/emitter.h

-- Up-to-date: /usr/local/include/yaml-cpp/emittermanip.h

-- Up-to-date: /usr/local/include/yaml-cpp/eventhandler.h

-- Up-to-date: /usr/local/include/yaml-cpp/exceptions.h

-- Up-to-date: /usr/local/include/yaml-cpp/iterator.h

-- Up-to-date: /usr/local/include/yaml-cpp/ltnode.h

-- Up-to-date: /usr/local/include/yaml-cpp/mark.h

-- Up-to-date: /usr/local/include/yaml-cpp/node.h

-- Up-to-date: /usr/local/include/yaml-cpp/nodeimpl.h

-- Up-to-date: /usr/local/include/yaml-cpp/nodereadimpl.h

-- Up-to-date: /usr/local/include/yaml-cpp/nodeutil.h

-- Up-to-date: /usr/local/include/yaml-cpp/noncopyable.h

-- Up-to-date: /usr/local/include/yaml-cpp/null.h

-- Up-to-date: /usr/local/include/yaml-cpp/ostream.h

-- Up-to-date: /usr/local/include/yaml-cpp/parser.h

-- Up-to-date: /usr/local/include/yaml-cpp/stlemitter.h

-- Up-to-date: /usr/local/include/yaml-cpp/stlnode.h

-- Up-to-date: /usr/local/include/yaml-cpp/traits.h

-- Up-to-date: /usr/local/include/yaml-cpp/yaml.h

-- Up-to-date: /usr/local/include/yaml-cpp/anchordict.h

-- Up-to-date: /usr/local/include/yaml-cpp/graphbuilder.h

-- Installing: /usr/local/lib/pkgconfig/yaml-cpp.pc

使用libyaml进行编译时,可能必须在gcc命令后附加一些特殊的指令/选项吗?像gcc main.cpp -libyaml?

有关编译器的更多输出(ѭ9more):

/tmp/ccYltArL.o: In function `operator>>(YAML::Node const&, Monster&)\':

main.cpp:(.text+0x1a8): undefined reference to `YAML::Node::size() const\'

/tmp/ccYltArL.o: In function `main\':

main.cpp:(.text+0x1fe): undefined reference to `std::basic_ifstream >::basic_ifstream(char const*, std::_Ios_Openmode)\'

main.cpp:(.text+0x215): undefined reference to `YAML::Parser::Parser(std::basic_istream >&)\'

main.cpp:(.text+0x224): undefined reference to `YAML::Node::Node()\'

main.cpp:(.text+0x23e): undefined reference to `YAML::Parser::GetNextDocument(YAML::Node&)\'

main.cpp:(.text+0x29c): undefined reference to `std::cout\'

还有比这里更多的东西

,最后以:

/tmp/ccYltArL.o:(.rodata._ZTIN4YAML14BadDereferenceE[typeinfo for YAML::BadDereference]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info\'

/tmp/ccYltArL.o:(.rodata._ZTIN4YAML11KeyNotFoundE[typeinfo for YAML::KeyNotFound]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info\'

/tmp/ccYltArL.o:(.rodata._ZTIN4YAML13InvalidScalarE[typeinfo for YAML::InvalidScalar]+0x0): more undefined references to `vtable for __cxxabiv1::__si_class_type_info\' follow

/tmp/ccYltArL.o:(.rodata._ZTIN4YAML9ExceptionE[typeinfo for YAML::Exception]+0x8): undefined reference to `typeinfo for std::runtime_error\'

/tmp/ccYltArL.o:(.eh_frame+0x18f): undefined reference to `__gxx_personality_v0\'

collect2: ld returned 1 exit status

-终于-

用克里斯的解决方案解决了这个问题(请参阅下文),尽管我实际上找到了一种更简单的预加载“自定义”库的方法,方法是在将路径添加到我的库之后,使用ldconfig命令配置库搜索路径在/etc/ld.so.conf.d/中解压缩为*.conf文件。在此处查看详细指南...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值