2013-05-11 50 views
0
使用boost ::序列化時

我試圖建立來自Boost演示::系列化頁:連接錯誤XCode中

#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沒有結果。

其他人都遇到過這個問題嗎?

Thnaks提前。

+0

如何對'.a'文件而不是'.dylib'文件進行鏈接(如果存在的話)? – trojanfoe 2013-05-11 20:24:58

+0

@trojanfoe:仍然收到相同的錯誤 – Kobe 2013-05-11 20:28:29

回答

0

你有這樣的警告嗎?

忽略文件您_lib_file_name,文件是專爲不支持的文件格式(等等等等等等),這是不被鏈接

它的架構,你有,嘗試用正確的配置來構建升壓。

+0

我相信你應該看看http://stackoverflow.com/questions/7361751/c-boost-on-iphone。我遇到了和你一樣的問題,這個提示幫助了我。 – 2013-06-13 14:17:50