A formalism is described to calculate capillary forces between solid surfaces analytically. Assumptions are that the liquid menisci (1) have a much larger extension parallel to the gap than normal and (2) are formed by capillary condensation and are in equilibrium with the vapor. To calculate capillary forces, first the gap between the two surfaces is described by a height distribution function. Roughness is considered with an asperity distribution function. Both distributions can at least in principal be measured by light, electron, or atomic force microscopy or grazing incidence X-ray reflectivity. The total capillary force versus distance or vapor pressure is obtained by a convolution of both distributions and an integration. The formalism is applied to calculate the capillary force between rough spherical particles. In addition, a method to consider surface heterogeneity is suggested.