libpqxx: undefined reference to `pqxx::argument_error::argument_error`

Hello there! I have got some linking error:

/usr/bin/ld: /tmp/ccadqyKa.o: in function `pqxx::internal::(anonymous namespace)::throw_for_encoding_error(char const*, char const*, unsigned long, unsigned long)': db.cpp:(.text+0x1dc): undefined reference to `pqxx::argument_error::argument_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::source_location)' /usr/bin/ld: /tmp/ccpFKSJv.o: in function `pqxx::internal::(anonymous namespace)::throw_for_encoding_error(char const*, char const*, unsigned long, unsigned long)': echo.cpp:(.text+0x1dc): undefined reference to `pqxx::argument_error::argument_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::source_location)' /usr/bin/ld: /tmp/ccJw3CDF.o: in function `pqxx::internal::(anonymous namespace)::throw_for_encoding_error(char const*, char const*, unsigned long, unsigned long)': main.cpp:(.text+0x1dc): undefined reference to `pqxx::argument_error::argument_error(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::source_location)' collect2: error: ld returned 1 exit status

As I see my source doesn’t matter. It comes from the header <pqxx/pqxx> Also both variants give the same error: -lpqxx -lpq /usr/local/lib/libpqxx.a -lpq

g++ (Debian 13.2.0-1) 13.2.0 psql (PostgreSQL) 15.4 (Debian 15.4-1)

Any advice please?

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Comments: 47 (36 by maintainers)

Commits related to this issue

Most upvoted comments

I think I finally have something working for this: #747.

@jtv Generating files in the CMake configuration step is a tricky task (compared to autotools).

First, I would like to explain the CMake steps, as I think it is important to familiarize yourself with each step of CMake. CMake has three main steps: configure-step, generate-step and build-step. Autotools users would like to think that . /configure and make, but unfortunately this is not the case.

configure-step: parses CMakeLists.txt to check the project structure and defined variables. generate-step: generates project files for native build tools based on the information obtained by configure-step. build-step: invokes the native build tool to build the artifact from the generated project file.

Tip The following sites explain each step in more detail: https://cgold.readthedocs.io/en/latest/tutorials/cmake-stages.html

It is important to note that CMake generates project files that are buildable by native build tools, but leaves the building to the native build tools. And since CMake is a cross-platform tool, it does not support tasks that can only be performed with specific build tools.

In autotools, . /configure can generate additional files, but the equivalent functionality is not supported by other build tools (for example, Visual Studio IDE does not have the ability to automatically generate files when a project is opened.). Since all native build tools can generate files, the build commands executed by CMake build-step, add_custom_command() and add_custom_target(), which generate files in build-step, are commonly used in CMake file generation.

The add_custom_command() and add_custom_target(), which are commonly used in CMake for file generation, work on all platforms because they utilize the functionality of the native build tools. However, since they are executed by CMake build-step, they will not work in this case.

The best match for this case would be execute_process(). The execute_process invokes a command (external process) with CMake configure-step. The external process can generate files.

Note CMake support for the external process is not very good. This is because the external process is launched while CMake is reading the project configuration.

The community recommends add_custom_command over execute_process: https://discourse.cmake.org/t/execute-process-vs-add-custom-command/3286

Another solution that exists in CMake is try_compile. try_compile is used in https://github.com/jtv/libpqxx/blob/7.8.1/cmake/config.cmake try_compile can be used in combination with configure_file to record whether a feature is supported. The user can control the contents of the file generated by configure_file by predefining variables to be set by try_compile.

Alright then. I’ll have to go back to writing more config into a header at configure time.

I’d like to avoid duplicating checks between build systems, of course. Perhaps I can run the compiler in a way that tells me all defined macros, and sort it out from there in a single python script.

For those who came here because the latest Arch linux package with libpqxx 7.8.1+ suffers from this issue and need a quick fix, here is an updated PKGBUILD with C++20 flag enabled, although it is hardly a permanent solution.

Guys, sorry for the delay with answer. I had to rebuild the lib with the following flags: ./configure --disable-shared CXX=g++ CXXFLAGS=-std=c++20

Now, my source compiles together with <pqxx/pqxx>, std::chrono inside and with -std=c++20 flag.

So, it means the library building must be made with -std=c++20 flag if your compiler gcc version is 13 and\or your compiler supports c++20.

Thank you all and @tt4g