2011-04-21 55 views
11

我需要(de)序列化Windows和Linux上的數據(並在兩者之間傳輸文件)。我想使用可在示例中找到的Boost序列化庫的便攜式二進制歸檔文件,請參閱在http://boost-doc-zh.googlecode.com/svn-history/r380/trunk/libs/serialization/example/便攜式歸檔沒有在GCC下編譯

這適用於Windows(VS 2008),但在GCC 4.3.2下無法編譯,但出現以下錯誤。

有人可以提出一個解決方案嗎?

非常感謝!

/projects/lib/BOOST/1_44_0/include/boost/archive/basic_archive.hpp: In member function 'void portable_binary_iarchive::init(unsigned int)': 
/projects/lib/BOOST/1_44_0/include/boost/archive/basic_archive.hpp:78: error: 'uint_least32_t boost::archive::version_type::t' is private 
/home/myfolder/src/portable_binary_iarchive.cpp:92: error: within this context 
/home/myfolder/src/portable_binary_iarchive.hpp: In member function 'void portable_binary_iarchive::load(T&) [with T = boost::archive::class_id_type]': 
/projects/lib/BOOST/1_44_0/include/boost/archive/detail/iserializer.hpp:107: instantiated from 'static void boost::archive::load_access::load_primitive(Archive&, T&) [with Archive = portable_binary_iarchive, T = boost::archive::class_id_type]' 
/projects/lib/BOOST/1_44_0/include/boost/archive/detail/iserializer.hpp:356: instantiated from 'static void boost::archive::detail::load_non_pointer_type<Archive>::load_primitive::invoke(Archive&, T&) [with T = boost::archive::class_id_type, Archive = portable_binary_iarchive]' 
/projects/lib/BOOST/1_44_0/include/boost/archive/detail/iserializer.hpp:433: instantiated from 'static void boost::archive::detail::load_non_pointer_type<Archive>::invoke(Archive&, T&) [with T = boost::archive::class_id_type, Archive = portable_binary_iarchive]' 
/projects/lib/BOOST/1_44_0/include/boost/archive/detail/iserializer.hpp:586: instantiated from 'void boost::archive::load(Archive&, T&) [with Archive = portable_binary_iarchive, T = boost::archive::class_id_type]' 
/projects/lib/BOOST/1_44_0/include/boost/archive/detail/common_iarchive.hpp:66: instantiated from 'void boost::archive::detail::common_iarchive<Archive>::load_override(T&, int) [with T = boost::archive::class_id_type, Archive = portable_binary_iarchive]' 
/home/myfolder/src/portable_binary_iarchive.hpp:140: instantiated from 'void portable_binary_iarchive::load_override(T&, int) [with T = boost::archive::class_id_type]' 
/projects/lib/BOOST/1_44_0/include/boost/archive/detail/interface_iarchive.hpp:60: instantiated from 'Archive& boost::archive::detail::interface_iarchive<Archive>::operator>>(T&) [with T = boost::archive::class_id_type, Archive = portable_binary_iarchive]' 
/projects/lib/BOOST/1_44_0/include/boost/archive/detail/common_iarchive.hpp:51: instantiated from 'void boost::archive::detail::common_iarchive<Archive>::vload(boost::archive::class_id_type&) [with Archive = portable_binary_iarchive]' 
/home/myfolder/src/portable_binary_iarchive.cpp:128: instantiated from here 
/home/myfolder/src/portable_binary_iarchive.hpp:107: error: call of overloaded 'class_id_type(intmax_t&)' is ambiguous 
/projects/lib/BOOST/1_44_0/include/boost/archive/basic_archive.hpp:118: note: candidates are: boost::archive::class_id_type::class_id_type(size_t) 
/projects/lib/BOOST/1_44_0/include/boost/archive/basic_archive.hpp:115: note:     boost::archive::class_id_type::class_id_type(int) 

回答

1

對於您的問題並非真正直接的答案,但我在Google的Protocol Buffers方面取得了很多成功。他們在內部使用它們並開放源代碼:http://code.google.com/p/protobuf/

+0

謝謝,但我知道protobuf,它不適合我的建築。所以我正在尋找一種Boost Serialization的方式來做到這一點。 – Philipp 2011-04-24 05:35:21

0

我用g ++ 4.1.2構建,它工作正常。我討厭bjam,很難看到發生了什麼,而且速度很慢。 有一個關於不推薦使用的標題的警告,因爲這有一個棄用的朋友聲明的標記,所以我希望看到一些舊的,但我不知道。

你用bjam構建它還是你試圖將序列化插入到你自己的目錄中並自己做?因爲你的目錄結構不完全像它們在包中的那樣。

0
#define private public 

應該擺脫關於訪問私有成員的第一個錯誤。這有點厚臉皮!但它可以作爲一個臨時修復,直到你更好地理解整個程序。

+0

這是否有可能破壞其他代碼? – shuttle87 2011-06-01 22:49:29

+0

我認爲這樣做是安全的。我從來沒有自己做過,除了測試它的工作。另一種方法是將它通過命令行傳遞給編譯'g ++ -Dprivate = public prog.cpp -o prog'。當然,您有責任確保您正確處理私人數據。但是如果你正確理解那個類的內部,你應該能夠以合理的方式與它進行交互。 – 2011-06-02 11:03:00