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
- Feature-test macros + config header! We're getting bug reports (e.g. #732) for situations where people have a libpqxx compiled as C++17 but an application compiled as C++20, or _vice versa._ General... — committed to jtv/libpqxx by jtv 8 months ago
- Generate feature test, in two stages. This is yet another attempt at #732: go back to writing all feature test macros to a config header, so that we can build libpqxx itself and the client applicatio... — committed to jtv/libpqxx by jtv 8 months ago
- Generate feature tests, in two stages. (#747) Generate feature tests, in two stages. This is yet another attempt at #732: go back to writing all feature test macros to a config header, so that we... — committed to jtv/libpqxx by jtv 7 months ago
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
. /configureandmake, but unfortunately this is not the case.configure-step: parses
CMakeLists.txtto 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.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,
. /configurecan 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()andadd_custom_target(), which generate files in build-step, are commonly used in CMake file generation.The
add_custom_command()andadd_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(). Theexecute_processinvokes a command (external process) with CMake configure-step. The external process can generate files.Another solution that exists in CMake is
try_compile.try_compileis used in https://github.com/jtv/libpqxx/blob/7.8.1/cmake/config.cmaketry_compilecan be used in combination withconfigure_fileto record whether a feature is supported. The user can control the contents of the file generated byconfigure_fileby predefining variables to be set bytry_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++20Now, 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