在XCode中使用Boost :: Serialization时出现链接器错误

时间:2013-05-11 20:13:33

标签: c++ xcode macos boost boost-serialization

我正在尝试从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 我已经添加了标题(标题搜索路径)和库(库搜索路径)的路径,还在链接二进制文件中添加了libboost_serialization.dylib和库。

在其他线程中搜索我的问题似乎是我没有告诉编译器静态库libboost_serialization.a。我该怎么做呢 ? (如果这是我的问题)。我尝试添加到其他链接器标志,如下所示:-lboost_serialization没有结果。

其他人遇到过这个问题?

提前做好准备。

1 个答案:

答案 0 :(得分:0)

你有这样的警告吗?

  

忽略文件你的_lib_file_name ,文件是为不支持的文件格式(blah blah blah)构建的,这不是被链接的体系结构

你有,试着用适当的配置来构建助推器。