That is a problem with boost::phoenix V2 (don't ask which ;-)) So, using V3 will work.
Additionally one has to give the attribute to the int generator and reference the lineNum when printing it.
#include <iostream>
#include <string>
#define BOOST_SPIRIT_USE_PHOENIX_V3
#include <boost/spirit/include/karma.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
int main() {
using boost::spirit::karma::eps;
using boost::spirit::karma::int_;
using boost::spirit::karma::lit;
using boost::spirit::karma::eol;
using boost::spirit::karma::_1;
using boost::spirit::karma::_val;
using boost::phoenix::val;
using boost::phoenix::ref;
using boost::spirit::karma::generate;
using boost::spirit::karma::rule;
typedef std::back_insert_iterator<std::string> OutputIteratorType;
std::string s;
std::back_insert_iterator<std::string> sink(s);
int lineNum = 0;
rule<OutputIteratorType, int()> testRule = eps[ref(lineNum) += 10]
<< lit("Line number ") << lit(ref(lineNum)) << lit(": ")
<< int_[_1 = _val] << eol;
generate(sink, testRule, 123);
generate(sink, testRule, 123);
std::cout << s;
return 0;
}