I was just reading "Creating Library with backward compatible ABI that uses Boost". Now I have a class that is supposed to be serialised using boost. How can I hide that part from the public interface? In the article mentioned it was suggested to use the -fvisibility=hidden option of gcc. I tried to implement this in a test class:
#define LOCAL __attribute__ ((visibility ("hidden")))
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/serialization.hpp>
#include <boost/shared_ptr.hpp>
class hideBoost
{
public:
int visible;
LOCAL boost::shared_ptr<int> notVisible;
private:
friend class boost::serialization::access;
template<class archive>
void serialize(archive& ar, const unsigned int version)
{
ar & BOOST_SERIALIZATION_NVP(visible);
ar & BOOST_SERIALIZATION_NVP(notVisible);
}
};
And my main program is:
#include <iostream>
#include "HideBoost.hpp"
int main()
{
std::cout<<"start"<<std::endl;
hideBoost b;
b.visible=5;
b.notVisible=10;
std::cout<<"end"<<std::endl;
}
Both are compiled using gcc-4.6 on MacOSX with the flag -fvisibility=hidden
.
EDIT: The main program does not have to boost headers at compile time and therefore compilation fails. I do not want to pass the boost headers to the main program since this can lead to incompatibilities on systems that have more than one version of boost installed (I guess this is called ABI incompatibility).
Now my question:
1) Is the member variable notVisible
in my example properly hidden from the public interface?
2) EDIT: How can I hide the serialisation routine and the header files?
I'm thankful to any hints how this can be done properly. A solution that works using gcc and clang on unix and OS X would be great. Thanks in advance!
Best wishes, Peter