我尝试使用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.
所有libs都已正确安装
/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?
答案 0 :(得分:1)
您没有编译或链接器错误,只是发出警告。
所以,你应该能够运行你的脚本了。
[UPDATE]
此外,在您的C ++脚本中, #pragma link 指令指定的库没有双引号。涉及编译指示指令的所有G-WAN示例都使用双引号 - 顺便说一下,C标准中的字符串是强制性的:
#pragma link "pqxx"
#pragma link "pq"