How do you allow non-root users to access I2C on the Raspberry Pi 2?

I've compiled [this code](https://github.com/jrowberg/i2cdevlib/blob/master/RaspberryPi_bcm2835/MPU6050/examples/MPU6050_example_1.cpp) for accessing an MPU6050 sensor via I2C, and it works perfectly, but only when I call it via sudo.

I tried adding the pi user to the spi and i2c groups, and adding udev rules as explained [here](http://quick2wire.com/non-root-access-to-spi-on-the-pi/) and [here](https://github.com/fivdi/i2c-bus/blob/master/doc/raspberry-pi-i2c.md), but even after rebooting, those had little effect. I can run `/usr/sbin/i2cdetect` as a non-root user, but the C code `I2Cdev::initialize()` still crashes if run without sudo.

This is documented in the [underlying bcm2835 library](http://www.airspayce.com/mikem/bcm2835/):

> 
> If the library runs with any other effective UID (ie not root), then
>  bcm2835\_init() will attempt to open /dev/gpiomem, and, if successful,
>  will only permit GPIO operations. In particular, bcm2835\_spi\_begin()
>  and bcm2835\_i2c\_begin() will return false and all other non-gpio
>  operations may fail silently or crash.
> 
> 
> 

Is there any workaround for this? Even if I add the pi user to the root group, it still silently crashes.