c++codelitelibpqxx

Codelite using libpqxx connect example with g++ fails on macosx


I've tried both make and cmake to compile and deploy libpqxx but simple code does not seem to work. https://github.com/jtv/libpqxx/blob/master/BUILDING-configure.md. I installed the library using the instructions on the official Git repo but am still getting issues with build step in Codelite project.

Codelite project configuration:

  1. Makefile generator Default
  2. Compiler GCC
  3. Compiler options: -g;-O0;-Wall -lpqxx -lpq

I can see the libpqxx libraries when I list installed libraries:

lrwxr-xr-x    1 thomaspeters  staff     48 Aug 17 22:50 postgres_ext.h -> ../Cellar/postgresql/13.4/include/postgres_ext.h
lrwxr-xr-x    1 thomaspeters  staff     44 Aug 17 22:50 postgresql -> ../Cellar/postgresql/13.4/include/postgresql
drwxr-xr-x  129 root          staff   4128 Sep 12 02:05 pqxx

I have postgres client libs and pqxx libs installed. Notices the ownership is set to root. Is this a permissions issue?

#include <iostream>
#include <pqxx/pqxx> 

using namespace std;
using namespace pqxx;

int main(int argc, char* argv[]) {
   try {
      connection C("dbname = testdb user = postgres password = cohondob \
      hostaddr = 127.0.0.1 port = 5432");
      if (C.is_open()) {
         cout << "Opened database successfully: " << C.dbname() << endl;
      } else {
         cout << "Can't open database" << endl;
         return 1;
      }
      C.disconnect ();
   } catch (const std::exception &e) {
      cerr << e.what() << std::endl;
      return 1;
   }
}

My example code produces the following build stream. Seems like a compatibility issue with standard versions of c++ compiler.

/usr/bin/make -j16 -e -f  Makefile
----------Building project:[ pgSample - Debug ]----------
clang: warning: -lpqxx: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lpq: 'linker' input unused [-Wunused-command-line-argument]
/usr/bin/g++  -c  "/Users/thomaspeters/Documents/Development/C-Simple-Projects/C-Simple-Projects/pgSample/main.cpp" -g -O0 -Wall -lpqxx -lpq  -o Debug/main.cpp.o -I. -I.
clang: warning: -lpqxx: 'linker' input unused [-Wunused-command-line-argument]
clang: warning: -lpq: 'linker' input unused [-Wunused-command-line-argument]
In file included from /Users/thomaspeters/Documents/Development/C-Simple-Projects/C-Simple-Projects/pgSample/main.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:2:
In file included from /usr/local/include/pqxx/array:4:
In file included from /usr/local/include/pqxx/array.hxx:17:
/usr/local/include/pqxx/internal/encoding_group.hxx:14:15: warning: nested namespace definition is a C++17 extension; define each namespace separately [-Wc++17-extensions]
namespace pqxx::internal
              ^~~~~~~~~~
               { namespace internal
/usr/local/include/pqxx/internal/encoding_group.hxx:18:6: warning: scoped enumerations are a C++11 extension [-Wc++11-extensions]
enum class encoding_group
     ^
/usr/local/include/pqxx/internal/encoding_group.hxx:53:3: warning: alias declarations are a C++11 extension [-Wc++11-extensions]
  std::size_t(char const buffer[], std::size_t buffer_len, std::size_t start);
  ^
In file included from /Users/thomaspeters/Documents/Development/C-Simple-Projects/C-Simple-Projects/pgSample/main.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:2:
In file included from /usr/local/include/pqxx/array:4:
In file included from /usr/local/include/pqxx/array.hxx:18:
/usr/local/include/pqxx/internal/encodings.hxx:18:15: warning: nested namespace definition is a C++17 extension; define each namespace separately [-Wc++17-extensions]
namespace pqxx::internal
              ^~~~~~~~~~
               { namespace internal
/usr/local/include/pqxx/internal/encodings.hxx:58:3: warning: 'auto' type specifier is a C++11 extension [-Wc++11-extensions]
  auto const scan{get_glyph_scanner(enc)};
  ^
/usr/local/include/pqxx/internal/encodings.hxx:58:14: error: declaration of variable 'scan' with deduced type 'const auto' requires an initializer
  auto const scan{get_glyph_scanner(enc)};
             ^
/usr/local/include/pqxx/internal/encodings.hxx:58:18: error: expected ';' at end of declaration
  auto const scan{get_glyph_scanner(enc)};
                 ^
                 ;
In file included from /Users/thomaspeters/Documents/Development/C-Simple-Projects/C-Simple-Projects/pgSample/main.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:2:
In file included from /usr/local/include/pqxx/array:4:
/usr/local/include/pqxx/array.hxx:50:8: warning: scoped enumerations are a C++11 extension [-Wc++11-extensions]
  enum class juncture
       ^
/usr/local/include/pqxx/array.hxx:82:32: warning: default member initializer for non-static data member is a C++11 extension [-Wc++11-extensions]
  std::string::size_type m_pos = 0u;
                               ^
/usr/local/include/pqxx/array.hxx:67:42: warning: use of enumeration in a nested name specifier is a C++11 extension [-Wc++11-extensions]
    internal::encoding_group = internal::encoding_group::MONOBYTE);
                                         ^
In file included from /Users/thomaspeters/Documents/Development/C-Simple-Projects/C-Simple-Projects/pgSample/main.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:3:
In file included from /usr/local/include/pqxx/binarystring:4:
In file included from /usr/local/include/pqxx/binarystring.hxx:21:
In file included from /usr/local/include/pqxx/result.hxx:23:
/usr/local/include/pqxx/except.hxx:89:11: error: exception specification of overriding function is more lax than base version
  virtual ~sql_error() noexcept override;
          ^
/usr/local/include/pqxx/except.hxx:42:23: note: overridden virtual function is here
struct PQXX_LIBEXPORT failure : std::runtime_error
                      ^
/usr/local/include/pqxx/except.hxx:89:23: error: expected ';' at end of declaration list
  virtual ~sql_error() noexcept override;
                      ^
                      ;
/usr/local/include/pqxx/except.hxx:92:4: error: expected expression
  [[nodiscard]] PQXX_PURE std::string const &query() const noexcept;
   ^
/usr/local/include/pqxx/except.hxx:92:17: error: expected member name or ';' after declaration specifiers
  [[nodiscard]] PQXX_PURE std::string const &query() const noexcept;
                ^
/usr/local/include/pqxx/compiler-public.hxx:25:21: note: expanded from macro 'PQXX_PURE'
#  define PQXX_PURE __attribute__((pure))
                    ^
In file included from /Users/thomaspeters/Documents/Development/C-Simple-Projects/C-Simple-Projects/pgSample/main.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:3:
In file included from /usr/local/include/pqxx/binarystring:4:
In file included from /usr/local/include/pqxx/binarystring.hxx:21:
In file included from /usr/local/include/pqxx/result.hxx:23:
/usr/local/include/pqxx/except.hxx:95:4: error: expected expression
  [[nodiscard]] PQXX_PURE std::string const &sqlstate() const noexcept;
   ^
/usr/local/include/pqxx/except.hxx:95:17: error: expected member name or ';' after declaration specifiers
  [[nodiscard]] PQXX_PURE std::string const &sqlstate() const noexcept;
                ^
/usr/local/include/pqxx/compiler-public.hxx:25:21: note: expanded from macro 'PQXX_PURE'
#  define PQXX_PURE __attribute__((pure))
                    ^
In file included from /Users/thomaspeters/Documents/Development/C-Simple-Projects/C-Simple-Projects/pgSample/main.cpp:2:
In file included from /usr/local/include/pqxx/pqxx:3:
In file included from /usr/local/include/pqxx/binarystring:4:
In file included from /usr/local/include/pqxx/binarystring.hxx:21:
In file included from /usr/local/include/pqxx/result.hxx:23:
/usr/local/include/pqxx/except.hxx:201:71: error: expected member name or ';' after declaration specifiers
  explicit unexpected_rows(std::string const &msg) : range_error{msg} {}
                                                                      ^
/usr/local/include/pqxx/except.hxx:201:65: error: expected '('
  explicit unexpected_rows(std::string const &msg) : range_error{msg} {}
                                                                ^
/usr/local/include/pqxx/except.hxx:201:69: error: expected ';' after expression
  explicit unexpected_rows(std::string const &msg) : range_error{msg} {}
                                                                    ^
                                                                    ;
/usr/local/include/pqxx/except.hxx:201:66: warning: expression result unused [-Wunused-value]
  explicit unexpected_rows(std::string const &msg) : range_error{msg} {}
                                                                 ^~~
/usr/local/include/pqxx/except.hxx:212:3: error: expected member name or ';' after declaration specifiers
  {}
  ^
/usr/local/include/pqxx/except.hxx:211:20: error: expected '('
          sql_error{err, Q, sqlstate}
                   ^
/usr/local/include/pqxx/except.hxx:211:21: warning: expression result unused [-Wunused-value]
          sql_error{err, Q, sqlstate}
                    ^~~
/usr/local/include/pqxx/except.hxx:211:26: warning: expression result unused [-Wunused-value]
          sql_error{err, Q, sqlstate}
                         ^
/usr/local/include/pqxx/except.hxx:211:37: error: expected ';' after expression
          sql_error{err, Q, sqlstate}
                                    ^
                                    ;
/usr/local/include/pqxx/except.hxx:211:29: warning: expression result unused [-Wunused-value]
          sql_error{err, Q, sqlstate}
                            ^~~~~~~~
/usr/local/include/pqxx/except.hxx:222:3: error: expected member name or ';' after declaration specifiers
  {}
  ^
/usr/local/include/pqxx/except.hxx:221:20: error: expected '('
          sql_error{err, Q, sqlstate}
                   ^
/usr/local/include/pqxx/except.hxx:221:21: warning: expression result unused [-Wunused-value]
          sql_error{err, Q, sqlstate}
                    ^~~
/usr/local/include/pqxx/except.hxx:221:26: warning: expression result unused [-Wunused-value]
          sql_error{err, Q, sqlstate}
                         ^
/usr/local/include/pqxx/except.hxx:221:37: error: expected ';' after expression
          sql_error{err, Q, sqlstate}
                                    ^
                                    ;
/usr/local/include/pqxx/except.hxx:221:29: warning: expression result unused [-Wunused-value]
          sql_error{err, Q, sqlstate}
                            ^~~~~~~~
/usr/local/include/pqxx/except.hxx:231:3: error: expected member name or ';' after declaration specifiers
  {}
  ^
/usr/local/include/pqxx/except.hxx:230:20: error: expected '('
          sql_error{err, Q, sqlstate}
                   ^
/usr/local/include/pqxx/except.hxx:230:21: warning: expression result unused [-Wunused-value]
          sql_error{err, Q, sqlstate}
                    ^~~
/usr/local/include/pqxx/except.hxx:230:26: warning: expression result unused [-Wunused-value]
          sql_error{err, Q, sqlstate}
                         ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
17 warnings and 20 errors generated.
make[1]: *** [Debug/main.cpp.o] Error 1
make: *** [All] Error 2
==== build ended with errors (20 errors, 46 warnings) ===

Solution

  • Just learning and still got a long way to go, but discovered some linker options to make the compiler behave differently. I was able to remove all compiler warnings, linker warnings and now my code compiles.

    using: -std=cxx17

    in C++ Linker options which causes the compiler to use cxx2017 standards. Uhh, still need some reading on that one. I can understand it, but not deeply as yet.

    Thomas