Question

I tried to use libpxx with G-WAN 4.3.14 , here's my original source code:

//#define USE_GWAN

#include <cstdio>
#include <iostream>
#include <pqxx/pqxx>
#ifdef USE_GWAN
#include "gwan.h"
#pragma link pqxx
#pragma link pq
#define print(x) xbuf_cat(get_reply(argv),x)
#else
#define print(x) printf(x)
#endif

using namespace std;
using namespace pqxx;
int main(int argc,char** argv) {
  char cstr[] = "dbname=censored user=censored password=censored hostaddr=127.0.0.1 port=5432";
  connection C(cstr);
  if(C.is_open()) {
    print("ok\n");
  } else {
    print("err\n");
  }
  return 200;
}

It's works fine when I tried to compile it normally:

g++ -lpqxx -lpq pg.cpp

But when I uncomment the //#define USE_GWAN and tried it on G-WAN, it shows:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: pg.cpp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: cannot find -ltestn
collect2: error: ld returned 1 exit status

1|#include<cstdio>
2|#include<iostream>
3|#include "gwan.h"
4|#include<pqxx/pqxx>
5|#pragma link pqxx
6|#pragma link pq
7|
8|using namespace std;

Update: different error shows up when closing G-WAN and the run it again:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Error: pg.cpp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
gcc: error: user=censored: No such file or directory
gcc: error: password=censored: No such file or directory
gcc: error: hostaddr=127.0.0.1: No such file or directory
gcc: error: port=5432: No such file or directory

1|#define USE_GWAN
2|
3|#include <cstdio>
4|#include <iostream>
5|#include <pqxx/pqxx>
6|#ifdef USE_GWAN
7|#include "gwan.h"
8|#pragma link pqxx


To run G-WAN, you must fix the error(s) or remove this Servlet.

all libs are installed correctly

/usr/lib/libpq.so -> libpq.so.5.6*
/usr/lib/libpq.so.5 -> libpq.so.5.6*
/usr/lib/libpq.so.5.6*
/usr/lib/libpqxx-4.0.so*
/usr/lib/libpqxx.so -> libpqxx-4.0.so*

is there anything that I should add to use libpqxx with G-WAN?

Was it helpful?

Solution

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"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top