When tanks first appeared on the battlefield in WWI, they were meant to advance in front of the infantry, run over and stop astride the enemy trenches and then clear them with cannons and machine guns firing from either side. They were lightly armored and able to stop most small arms fire. At first, they were terrifying to German troops, but they quickly realized that a couple of field pieces up by the trenches were enough to wreck most any tank in existence at the time.
Today in modern warfare, there are plenty of options for dealing with a tank as an infantryman under attack, anti-tank mines, artillery, rocket-propelled shape charges, anti-tank missiles, and with the advent of radio communications gear, you can bring down artillery or an air strike on tanks attacking your position.
In the years between WWI and WWII, instant radio communications and close air support were just beginning to come into existence and various countries all worked on how to provide infantry with a portable weapon that could disable the existing tanks without requiring artillery so close to the front that it would be knocked out by shelling in advance of an attack by tanks.
From this came the idea of creating large-caliber anti-tank rifles that could punch through the thin armor of early tanks, cheaply and effectively. They were concealable, did not require a crew to operate and unlike cannons or aircraft, are much cheaper and could be mass-produced.