Move the 2 lines of code below at the top of your script:
#pragma link pqxx
#pragma link pq
They are currently lines #5 and #6 in your script.
G-WAN pragma directives should come first, before #includes
and conditional pre-processor commands (#ifdef
...).
[UPDATE]
Also, in your C++ script, #pragma link directives are specifying libraries without double-quotes. All G-WAN examples involving pragma directives use double-quotes - which by the way is mandatory for strings in the C standard:
#pragma link "pqxx"
#pragma link "pq"