Depending on how your backpack is made, you can sometimes run a regular leather belt through the backpack's waist belt, which would then buckle at the front, around and on the outside of the backpack's normal waist belt. This might require some strategic cutting of material on your backpack to sneak your "over-belt" through the back and around to the other side, but if you can successfully do this, you can mount many holsters to the outside of the backpack's waist belt to open carry your gun at the hip. This is probably the best way to carry a gun while backpacking. If you'd like a photo to help illustrate, let me know.
The problem with this strategy (same goes for the chest packs some people are suggesting) is that when you take your backpack off, you'll need to figure out what you're going to do with your gun. For me, during the day (i.e., not in camp), I just take care that I'm never too far from my backpack. Once in camp, I would normally transfer the OWB holster and the over-belt from my backpack to my pants, although the process does take more time than I'd like. I tried a bellyband holster at one point, but it wasn't for me. Not enough support.