Compact astrophysical objects like white dwarfs and neutron stars generate very strong magnetic fields. In their atmosphere, accretion disks, and the interstellar medium surrounding them, the predominant matter consists of hydrogen, helium and few-particle atoms and molecules. In this work, we have studied the effects of strong magnetic fields on light atomic and molecular systems like hydrogen molecular ions and antiprotonic helium. The full energy of the investigated systems is calculated in the Born-Oppenheimer approximation for a few low-lying electronic states. We investigate the case where the leading effect comes from the quadratic magnetic field term in the interaction Hamiltonian. The electronic energies and wavefunctions are computed in spheroidal coordinates by a finite difference method on a nonequidistant grid. The diamagnetic contributions to the total energy for an arbitrary value of the magnetic field strength are also calculated in perturbation theory. Then they are compared with the exact results, and where possible - with previous calculations. The electronic energy terms could be used for precise computations of the spectral lines of the hydrogen molecular ion and antiprotonic helium. This will allow searching for objects, like neutron stars and white dwarfs with strong magnetic fields, containing such molecular systems in their atmospheres or accretion discs. When the effects from the approximations are taken into account, the tabulated results presented in this work could also find an application in studies for much weaker magnetic field strengths existing in laboratory environments.