我尝试将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一起使用吗?
最佳答案
将下面两行代码移到脚本顶部:
#pragma link pqxx
#pragma link pq
它们当前是脚本中的第5行和第6行。
G-WAN编译指示应优先于
#includes
和条件预处理器命令(#ifdef
...)之前。[更新]
另外,在您的C++脚本中, #pragma链接指令指定的库没有双引号。所有涉及pragma指令的G-WAN示例都使用双引号-顺便说一句,这对于C标准中的字符串是必需的:
#pragma link "pqxx"
#pragma link "pq"
关于c++ - 在G-WAN中使用PostgreSQL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23239063/