I hear it often from power boaters, nothing ever matches. The compass says one thing, the GPS says another, and the autopilot heading is different. Which one is right? My answer is usually all of them to some degree, but when in doubt, trust the GPS/COG heading. Why It's a math thing assuming you have a decent fix, and you can check on that. The magnetic compass in the dash, as well as the autopilot digital compass are actually more prone to give you a wonky readings due to a variety of environmental factors.
I'll start with the venerable magnetic compass. This is old, very old technology that works perfectly as long as it's in a wood boat with no ferrous metal, or electrical wiring. Truth be told, this is rarely the case, and here is a simple example. The boat builder installs the compass that came from the factory perfectly calibrated. Also installed within inches is now a chart plotter, wiring harnesses, and even a nearby storage compartment to keep your steel screw driver, and hook pliers in. Calibrated it may have once been, but now no longer.