The smell of Cannabis repels many creatures that would otherwise eat it. There are exceptions ... budworms and spider mites are on the most wanted list.
Most of the odor compounds are simple hudrocarbons called mono-and sesquiterpenes. Citrusy piney smells are created by monoterpenes. Think of them as construction debris ... the plant is producing lots of isoprene (the building block of terpenes) to make the diterpene THC. Some of it gets diverted "unfinished", and some of that is finished by enzymatic processes into all that nice smell.
Dead pure THC is almost odorless. When heated it's faintly, vaguely piney. I'm betting that many of the odor chemicals in hash or aged oils are sesquiterpenes.
Monoterpenes are made from 2x isoprene. Sesqui... are made of three, and diterpenes, four.
cn