Copying my comment down here:
Got it to work!
It turns out that, if the firmware build fails, it won't tell you why. I ran the build command from here:
(for the Pixhawk 4, seperate commands can be found for other models)
After running the make command, I was told exactly what library was missing (don't remember which anymore), and I installed that library directly from the command line (for ubuntu, sudo apt install libraryname). I was then able to build and upload the firmware successfully through MATLAB