我正在尝试从 Boost::Serialization 页面构建一个演示:
#include <fstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
class gps_position
{
private:
friend class boost::serialization::access;
template<class Archive>
void serialize(Archive & ar, const unsigned int version)
{
ar & degrees;
ar & minutes;
ar & seconds;
}
int degrees;
int minutes;
float seconds;
public:
gps_position(){};
gps_position(int d, int m, float s) :
degrees(d), minutes(m), seconds(s)
{}
};
int main() {
std::ofstream ofs("filename");
const gps_position g(35, 59, 24.567f);
{
boost::archive::text_oarchive oa(ofs);
oa << g;
}
return 0;
}
但我收到以下链接器错误:
boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::save(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
(null): "boost::archive::text_oarchive_impl<boost::archive::text_oarchive>::text_oarchive_impl(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, unsigned int)", referenced from:
(null): "boost::archive::basic_text_oprimitive<std::__1::basic_ostream<char, std::__1::char_traits<char> > >::~basic_text_oprimitive()", referenced from:
(null): Linker command failed with exit code 1 (use -v to see invocation)
我在 Mountain Lion 和 XCode 4.6.2 中使用 boost 1.53.0。
我已经添加了标题(标题搜索路径)和库(库搜索路径)的路径,并且还在 Link Binary with Libraries 中添加了 libboost_serialization.dylib。
在其他线程中搜索我的问题似乎是我没有告诉编译器有关静态库 libboost_serialization.a 的信息。我该怎么做呢 ?(如果这是我的问题)。我尝试像这样添加到其他链接器标志:-lboost_serialization 没有结果。
其他人遇到过这个问题吗?
提前谢谢。