The HARP Collaboration has presented measurements of the double-differential π± production cross section in the range of momentum 100MeV/c⩽p⩽800MeV/c and angle 0.35rad⩽θ⩽2.15rad with proton beams hitting thin nuclear targets. In many applications the extrapolation to long targets is necessary. In this article the analysis of data taken with long (one interaction length) solid cylindrical targets made of carbon, tantalum, and lead is presented. The data were taken with the large-acceptance HARP detector in the T9 beam line of the CERN proton synchrotron. The secondary pions were produced by beams of protons with momenta of 5, 8, and 12GeV/c. The tracking and identification of the produced particles were performed using a small-radius cylindrical time projection chamber placed inside a solenoidal magnet. Incident protons were identified by an elaborate system of beam detectors. Results are obtained for the double-differential yields per target nucleon d2σ/dpdθ. The measurements are compared with predictions of the MARS and GEANT4 Monte Carlo simulations.