1

我尝试将 libpxx 与 G-WAN 4.3.14 一起使用,这是我的原始源代码:

//#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;
}

当我尝试正常编译时它工作正常:

g++ -lpqxx -lpq pg.cpp

但是当我取消注释//#define USE_GWAN并在 G-WAN 上尝试时,它显示:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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;

更新:关闭 G-WAN 并再次运行时出现不同的错误:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.

所有库都已正确安装

/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*

我应该添加什么以将 libpqxx 与 G-WAN 一起使用?

4

1 回答 1

1

将以下 2 行代码移动到脚本顶部:

#pragma link pqxx
#pragma link pq

它们当前是脚本中的第 5 行和第 6 行。

G-WAN pragma 指令应该首先出现,在#includes条件预处理器命令之前(#ifdef...)。

[更新]

此外,在您的 C++ 脚本中,#pragma 链接指令指定没有双引号的库。所有涉及 pragma 指令的 G-WAN 示例都使用双引号 - 顺便说一句,这对于 C 标准中的字符串是强制性的:

#pragma link "pqxx"
#pragma link "pq"
于 2014-04-23T19:53:37.893 回答