This is a surprisingly difficult issue, and I still haven't come up with a perfect solution.
@Blue Jays has part of the answer, in my opinion. I bought a 340pd specifically for the purpose, and it's light enough to be tolerable even in ultralight and "fastpacking" scenarios.
Where to put it is the trick. I haven't found any waist or shoulder holsters that work. I've had good success with a chest pack, but you'll need to adjust the sternum strap on the backpack - assuming it's adjustable. The draw, from a chest pack, is a bit slow, and most of them absolutely scream "gun!". I bought one in light blue, and attached corded earbuds in a visible location to try to make it look like a cell phone pouch.
I also carry in pouches attached to the hip belt, either integral with the pack or aftermarket add-on. I went so far as to make a stacked cardboard template of roughly the size of the gun to take with me to REI while backpack shopping. This obviously limits the size and weight of the gun, but even then, few packs have hip pouches big enough. Finding one of the right size, with a quick access method like a velcro pull tab, might be the best solution.
My last resort - and my primary carry method with a backpack - is to keep the gun in the lower pouch at the back of the pack. Both my multi-day "heavy" pack and my trail running "fastpacking" vest have such pouches. These have no zippers or buttons and "close" with just an elastic strap. They are meant, I'm sure, as a convenient place to stash frequently accessed items like gloves or snacks. They offer very little security, and getting to the gun without removing the pack requires some contortions. I just haven't yet found anything better.