We consider the most interesting case: you have to hang on the wall of lockers drywall, its thickness is not known what kind of drywall is also unknown.
Take a long plank, about a centimeter thick, but a little wider, better plywood. Chipboard and ordinary tree can crack.
To cabinets hung exactly fasten the bottom one more of the same thickness.
But I'm taking DSP, another I was not. Fasten our board for the entire length of the hanging cabinets.
The entire load will fall on the top board, so it should be fixed thoroughly. Drywall - material is brittle, so you need more mounting points to distribute the load.
Fasten the bottom board, so that under its own weight does not come off, and later her prizhmut wardrobes.
In the upper board can be screwed screws or hooks on which to hang cabinets. I for this purpose took the screws a little more than the set that secures the backboard board to the wall.
Now you can start putting up our closets: