Two options, and this can be verified on the ATF website.
Pinned and welded.
I generally opt for pinned and welded, though silver solder works just as well, it can discolor or ruin some metals.
SIlver solder is soldering (like a plumber would) with a special silver soldering materials, which can be bought at most places like brownells or midways and is expensive if you're only goign to do it once.
The way I pin and weld, I drill a hole through the flash hider/compensator and into the threads of the barrel. I do not drill through the barrell all the way, I just drill enough to drill to the flat bottom of the threads. Drop in a hardened steel pin and weld the pin in place. This WILL prevent you from removing the compensator without drilling out the pin and last I checked is ATF approved and looks much much better than welding the whole thing on.