Cracked masonry structures are analyzed here with respect to the unilateral contact and the stone- or brick-interlocking phenomena that arise on the crack-interfaces. On the assumption of elastic behaviour for the rest of the structure the static problem is formulated as a variational inequality problem or a hemivariational inequality problem in a more general context. The first problem is equivalent to a linearly constrained quadratic minimization problem. An appropriately modified optimization algorithm is introduced for the numerical solution of the problem