我尝试将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.
所有libs都已正确安装
/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?
答案 0 :(得分:1)
将以下两行代码移到脚本顶部:
#pragma link pqxx
#pragma link pq
它们目前是您脚本中的第5行和第6行。
G-WAN pragma指令应首先出现在#includes
和条件预处理器命令(#ifdef
...)之前。
[UPDATE]
此外,在您的C ++脚本中, #pragma link 指令指定的库没有双引号。涉及编译指示指令的所有G-WAN示例都使用双引号 - 顺便说一下,C标准中的字符串是强制性的:
#pragma link "pqxx"
#pragma link "pq"