<P> Nevertheless, records show that in the Kaiyuan era (713--742) of Emperor Xuanzong's reign, the general Zhang Yue built a wall 90 li (48 kilometres (30 mi)) to the north of Huairong (懷 戎; present - day Huailai County, Hebei), although it remains unclear whether he erected new walls or only reinforced the existing Northern Qi walls . </P> <P> The Great Wall, or the ruins of it, features prominently in the subset of Tang poetry known as biansai shi (邊塞 詩, "frontier verse") written by scholar - officials assigned along the frontier . Emphasizing the poets' loneliness and longing for home while hinting at the pointlessness of their posts, these frontier verses are characterized by imagery of desolate landscapes, including the ruins of the now - neglected Great Wall--a direct product of Tang's frontier policy . </P> <P> Han Chinese power during the tumultuous post-Tang era was represented by the Song dynasty (960--1279), which completed its unification of the Chinese states with the conquest of Wuyue in 971 . Turning to the north after this victory, in 979 the Song eliminated the Northern Han, ultimate successors to the Later Jin, but were unable to take the Sixteen Prefectures from the Liao dynasty . As a result of Song's military aggression, relations between the Song and Liao remained tense and hostile . One of the battlegrounds in the Song--Liao War was the Great Wall Gap (長城 口), so named because the southern Yan wall of the Warring States period crossed the Juma River here into Liao territory . The Great Wall Gap saw action in 979, 988--989, and 1004, and a Song fortress was built there in 980 . Intermittent wars between the Song and the Liao lasted until January 1005, when a truce was called and led to the Treaty of Chanyuan . This agreement, among other things, required the Song to pay tribute to the Liao, recognized the Song and Liao as equals, and demarcated the Song--Liao border, the course of which became more clearly defined in a series of subsequent bilateral agreements . Several stretches of the old Great Walls, including the Northern Qi Inner Wall near the Hengshan mountain range, became the border between the Song and the Liao . </P> <P> In the northwest, the Song were in conflict with the Western Xia, since they occupied what the Song considered as Chinese land lost during the Tang dynasty . The Song utilized the walls built during the reign of Qin's King Zhaoxiang of the Warring States period, making it the Song--Western Xia border, but the topography of the area was not as sharp and distinct as the Song--Liao defences to the east . The border general Cao Wei (曹 瑋; 973--1030) deemed the Old Wall itself insufficient to slow a Tangut cavalry attack, and had a deep trench dug alongside . This trench, between 15 and 20 metres (49 and 66 feet) in width and depth, proved an effective defence, but in 1002 the Tanguts caught the Song patrollers off guard and filled the trench to cross the Old Wall . Later, in 1042, the Tanguts turned the trench against the Song by removing the bridges over it, thereby trapping the retreating army of Ge Huaimin (葛懷敏) before annihilating it at the Battle of Dingchuan Fortress (定 川 寨). </P>

When did the great wall of china finished getting built