[cfe-dev] How to run clang-plugin with database connectivity

Akash Gulhane gulhane.akash at gmail.com
Fri Apr 5 23:12:45 PDT 2013


I have written postgerSql connectivity code in clang plugin as shown below.

class PrintFunctionNamesAction : public PluginASTAction {
      protected:
            ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
llvm::StringRef) {
            PGconn          *conn;
            PGresult        *res;
            int             rec_count;
            int             row;
            int             col;



         conn = PQconnectdb("dbname=a host=localhost user=user
password=user123");

         if (PQstatus(conn) == CONNECTION_BAD) {
                 puts("We were unable to connect to the database");
                 //break;
         }

         res = PQexec(conn,
                 "update people set phonenumber=\'8983194618\' where id=3");

         res = PQexec(conn,
                 "select lastname,firstname,phonenumber from people order
by id");

         if (PQresultStatus(res) != PGRES_TUPLES_OK) {
                puts("We did not get any data!");
                 //break;
         }

         rec_count = PQntuples(res);

         printf("We received %d records.\n", rec_count);
         puts("==========================");

         for (row=0; row<rec_count; row++) {
                 for (col=0; col<3; col++) {
                         printf("%s\t", PQgetvalue(res, row, col));
                 }
                 puts("");
         }

         puts("==========================");

         PQclear(res);

         PQfinish(conn);
    return new PrintFunctionsConsumer();
  }

It does not give any compile time error; but I am getting the following
error ar run time.

clang++ -cc1 -load ../../../../Release+Asserts/lib/libPrintFunctionNames.so
-plugin print-fns -plugin-arg-print-fns -lpq test.cpp
PrintFunctionNames arg = -lpq
clang++: symbol lookup error:
../../../../Release+Asserts/lib/libPrintFunctionNames.so: undefined symbol:
PQconnectdb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130406/e7f26db2/attachment.html>


More information about the cfe-dev mailing list