1

I am toying around with Boost::Process (1.64.0), using GCC 7.1.1, trying to force the use of vfork() when forking a process. I am greeted by a linker error for the following program:

#include <boost/process.hpp>

namespace bp = ::boost::process;

int main(void)
{
  bp::child c("ls", bp::posix::use_vfork);
  c.wait();
  return 0;
}

Using:

g++ use_vfork.cpp

The linker error generated is as follows

In function 'boost::process::detail::posix::executor >, boost::fusion::filter_view&, boost::process::detail::posix::use_vfork_ const&> const, boost::process::detail::is_initializer > > > >::operator()()': spawn_simple.cpp:(.text._ZN5boost7process6detail5posix8executorINS_6fusion10joint_viewINS4_5tupleIJNS2_12exe_cmd_initIcEEEEENS4_11filter_viewIKNS6_IJRA6_KcRNS2_8null_outILi1ELin1EEERKNS2_10use_vfork_EEEENS1_14is_initializerIN4mpl_3argILin1EEEEEEEEEEclEv[_ZN5boost7process6detail5posix8executorINS_6fusion10joint_viewINS4_5tupleIJNS2_12exe_cmd_initIcEEEEENS4_11filter_viewIKNS6_IJRA6_KcRNS2_8null_outILi1ELin1EEERKNS2_10use_vfork_EEEENS1_14is_initializerIN4mpl_3argILin1EEEEEEEEEEclEv]+0x31): undefined reference to `boost::process::detail::posix::executor >, boost::fusion::filter_view&, boost::process::detail::posix::use_vfork_ const&> const, boost::process::detail::is_initializer > > > >::invoke(mpl_::bool_, mpl_::bool_)'

As far as I know, Boost Process itself is header only, so why is it complaining about an undefined reference of boost::process<...>::invoke()?

I tried adding -lboost_system and -lboost_iostreams, but that does not solve the linker error.

Ton van den Heuvel
  • 10,157
  • 6
  • 43
  • 82

1 Answers1

2

It could be a documentation bug/omission: vfork support is conditionally compiled-in:

#define BOOST_POSIX_HAS_VFORK 1

So this works:

#include <boost/process.hpp>

namespace bp = ::boost::process;

int main(void)
{
    bp::child c("ls", bp::posix::use_vfork);
    c.wait();
    return 0;
}
sehe
  • 374,641
  • 47
  • 450
  • 633