2

I'm currently in the process of upgrading a C++ application make use of a PostgreSQL database. Since we are typically running on *nix based systems I'm currently working within the Windows Subsystem for Linux (WSL) and a Ubuntu distribution in particular. PostgreSQL 10 was install via apt-get and everything was upgraded before following the directions to build libpqxx on Unix-like systems.

As a very basic test I have a simple class that just includes the reference:

#include <pqxx/pqxx> 

However, building results in a (long) error log starting with the following:

[ 15%] Building CXX object src/CMakeFiles/Core.dir/Reporters/DbReporter.cpp.o
In file included from /usr/local/include/pqxx/array.hxx:18:0,
                 from /usr/local/include/pqxx/array:4,
                 from /usr/local/include/pqxx/pqxx:2,
                 from /mnt/c/Users/User/git/Simulation/src/Reporters/DbReporter.cpp:3:
/usr/local/include/pqxx/internal/encodings.hxx:26:42: error: ‘pqxx::internal::encoding_group pqxx::internal::enc_group’ redeclared as different kind of symbol
 encoding_group enc_group(std::string_view);

All of the errors that follow are of a similar nature with files under /pqxx/*. generating the errors. Typically for invalid declarations, functions not being part of the std namespace (which is not redefined in the application), or what appear to be syntax errors.

I suspect there is a mis-match between how the libpqxx library was built. How can I isolate and correct the problem?

rjzii
  • 14,236
  • 12
  • 79
  • 119
  • "... everything was upgraded before following the directions to build `libpqxx` on Unix-like systems." - And you had built and installed `libpqxx`, hadn't you? I suspect that, because then you tell about compiling an example which uses that library, which would be impossible without installed library. But otherwise your question doesn't claim that you have installed `libpqxx`. Could you make the question post a bit clear in that respect? And, concerning the title, you have a **compiler** errors, not a *linking* ones. – Tsyvarev Sep 05 '19 at 17:25
  • @Tsyvarev Title has been updated; however, I"m not sure I follow the rest of your comment. The directions for `libpqxx` on GitHub were followed without error so it should be installed on the system now. However, this application is the first one to use the library, so I don't have any other projects to compare it to within our build environment. – rjzii Sep 05 '19 at 18:59
  • I may incorrectly understand the phrase "... everything was upgraded before following the directions to build libpqxx on Unix-like systems.", but for me it means that you prepare everything to build the library.., but do not build it (yet). However, if you think this implies that you have actually built and installed the library, then so it be. Again, I do not request additional information about installing the library. It was just a confirmation request, whether you have installed it or not. – Tsyvarev Sep 05 '19 at 19:53
  • @Tsyvarev Yes, the library built and installed fine... but the problem ended up being buried in the CMakes file and a really simple on at that once identified. – rjzii Sep 05 '19 at 19:58

1 Answers1

3

While the logs from the build were a bit hard to parse; however, the line redeclared as different kind of symbol is a clue along with errors in the output such as the following:

/usr/local/include/pqxx/stream_from.hxx: In constructor ‘pqxx::stream_from::stream_from(pqxx::transaction_base&, const string&, Iter, Iter ’:
/usr/local/include/pqxx/stream_from.hxx:134:19: error: missing template arguments before ‘(’ token
     separated_list(",", columns_begin, columns_end)

These strongly imply that there is a syntax error in the code, despite the library building fine with the tool chain outlined by the developer. One significant point is that libpqxx is dependent upon C++17. The error ended up being in the CMakeLists.txt file:

set(CMAKE_CXX_STANDARD 14)

Indicating that despite the library being dependent upon C++17, the application was building with C++14. Update line to 17 corrected the problem and allowed the code to build. At which point CMakeLists.txt must also be updated to link correctly:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lpqxx -lpq")
set(PQXX /usr/local/include/pqxx)

find_library(PQXX_LIB pqxx)
find_library(PQ_LIB pq)

target_link_libraries(PROGRAM ${PQXX_LIB} ${PQ_LIB})
rjzii
  • 14,236
  • 12
  • 79
  • 119
  • This! This is the likely answer when encountering this problem. I was building an example with a "too simple" CMakeLists and I just did `#include ` then attempted to compile and it screamed.. – Mihai Aug 24 '22 at 14:01