将MySQL与G-WAN结合使用



我尝试将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("okn");
    delete con;
  } catch (sql::SQLException &e) {
    print("errn");    
  }
  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("okn");
     ^
/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("errn");    
     ^
 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("okn");
     ^
/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("errn");    
     ^
 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

我应该添加什么来将mysql-connector-c++与G-WAN一起使用吗?

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

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

[更新]

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

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

相关内容

  • 没有找到相关文章

最新更新