我尝试将mysql-connector-c++与G-WAN 4.3.14结合使用,这是我的原始源代码:

//#define USE_GWAN
#include<cstdio>
#include<iostream>
#include <cppconn/driver.h>
#include <cppconn/exception.h>
using namespace std;

#ifdef USE_GWAN
  #include "gwan.h"
  #pragma link mysqlcppconn
  #define print(x) xbuf_cat(get_reply(argv),x)
#else
  #define print(x) printf(x)
#endif

int main(int argc,char** argv) {
  try {
    sql::Driver *driver = get_driver_instance();
    sql::Connection *con = driver->connect("tcp://127.0.0.1:3306", "secret", "secret");
    print("ok\n");
    delete con;
  } catch (sql::SQLException &e) {
    print("err\n");
  }
  return 200;
}

当我尝试正常编译时,它工作正常:
g++ -lmysqlcppconn test.cpp

但是,当我取消注释//#define USE_GWAN并在G-WAN上尝试过时,它显示:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Warning: test.cpp
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/asd/gwan_linux64-bit/0.0.0.0_8088/#0.0.0.0/csp/test.cpp:
In function 'int main(int, char**)':
/csp/test.cpp:11:46: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   #define print(x) xbuf_cat(get_reply(argv),x)
                                              ^
/csp/test.cpp:20:5: note: in expansion of macro 'print'
     print("ok\n");
     ^
/csp/test.cpp:11:46: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   #define print(x) xbuf_cat(get_reply(argv),x)
                                              ^
/csp/test.cpp:23:5: note: in expansion of macro 'print'
     print("err\n");
     ^

 8|#ifdef USE_GWAN
 9|  #include "gwan.h"
10|  #pragma link mysqlcppconn
11!  #define print(x) xbuf_cat(get_reply(argv),x)
12|#else
13|  #define print(x) printf(x)
14|#endif
15|


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Linking test.cpp: undefined symbol: get_driver_instance
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/asd/gwan_linux64-bit/0.0.0.0_8088/#0.0.0.0/csp/test.cpp:
In function 'int main(int, char**)':
/csp/test.cpp:11:46: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   #define print(x) xbuf_cat(get_reply(argv),x)
                                              ^
/csp/test.cpp:20:5: note: in expansion of macro 'print'
     print("ok\n");
     ^
/csp/test.cpp:11:46: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
   #define print(x) xbuf_cat(get_reply(argv),x)
                                              ^
/csp/test.cpp:23:5: note: in expansion of macro 'print'
     print("err\n");
     ^

 8|#ifdef USE_GWAN
 9|  #include "gwan.h"
10|  #pragma link mysqlcppconn
11!  #define print(x) xbuf_cat(get_reply(argv),x)
12|#else
13|  #define print(x) printf(x)
14|#endif
15|


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

所有库均已正确安装
/usr/lib/libmysqlclient.a
/usr/lib/libmysqlclient.so -> libmysqlclient.so.18*
/usr/lib/libmysqlclient.so.18 -> libmysqlclient.so.18.0.0*
/usr/lib/libmysqlclient.so.18.0.0*
/usr/lib/libmysqlclient_r.a -> libmysqlclient.a
/usr/lib/libmysqlclient_r.so -> libmysqlclient.so*
/usr/lib/libmysqlclient_r.so.18 -> libmysqlclient.so*
/usr/lib/libmysqlclient_r.so.18.0.0 -> libmysqlclient.so*
/usr/lib/libmysqlcppconn.so -> libmysqlcppconn.so.7*
/usr/lib/libmysqlcppconn.so.7 -> libmysqlcppconn.so.7.1.1.3*
/usr/lib/libmysqlcppconn.so.7.1.1.3*
/usr/lib/libmysqld.a
/usr/lib/libmysqld.so -> libmysqld.so.18*
/usr/lib/libmysqld.so.18*
/usr/lib/libmysqlservices.a

我应该添加什么才能在G-WAN中使用mysql-connector-c++?

最佳答案

您没有编译或链接器错误,只有警告。

因此,您应该能够运行脚本。

[更新]

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

#pragma link "pqxx"
#pragma link "pq"

关于c++ - 在G-WAN上使用MySQL,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23250132/

10-16 13:32