Yes, that's how a 3-axis gyroscope works - the gyros' reference frame is not static so you need to maintain a representation of the
orientation of the gyroscope frame w.r.t. the static frame in order to interpret the rotations relative to the static frame.
The two common ways to represent the relative orientation of the gyro are with a quarternion, or a DCM (direction cosine matrix).
You need to find code that does one of these (or polish up your vector maths
Good keywords to search for are IMU and DCM