Question

I tried to use mysql-connector-c++ with G-WAN 4.3.14 , here's my original source code:

//#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;
}

It's works fine when I tried to compile it normally:

g++ -lmysqlcppconn test.cpp

But when I uncomment the //#define USE_GWAN and tried it on G-WAN, it shows:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.

all libs are installed correctly

/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

is there anything that I should add to use mysql-connector-c++ with G-WAN?

Was it helpful?

Solution

You don't have a compilation or linker error, you just have a warning.

So, you should be able to run your script.

[UPDATE]

Also, in your C++ script, #pragma link directives are specifying libraries without double-quotes. All G-WAN examples involving pragma directives use double-quotes - which by the way is mandatory for strings in the C standard:

#pragma link "pqxx"
#pragma link "pq"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top