libpqxx: Trying to use libpqxx on a cmake project, but getting errors

Hi, I dont know if this is the right channel, if not please direct me to it. I have a small project (one .h and one .cpp) where I include a compiled version of this project 7.4.1. I am able to include the <pqxx/pqxx> header and all that goes with it. In the link phase I am having the following error :

– Configuring done – Generating done – Build files have been written to: C:/code/NervesOfSteelProject/DatabaseNode/cmake-build-debug [ 50%] Building CXX object CMakeFiles/NOSDatabaseProcess.dir/NOSDatabaseProcess.cpp.obj [100%] Linking CXX executable NOSDatabaseProcess.exe CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj): In function __static_initialization_and_destruction_0': C:/code/NervesOfSteelProject/DatabaseNode/libpqxx/include/pqxx/strconv.hxx:76: undefined reference to pqxx::internal::demangle_type_name[abi:cxx11](char const*)’ C:/code/NervesOfSteelProject/DatabaseNode/libpqxx/include/pqxx/strconv.hxx:76: undefined reference to pqxx::internal::demangle_type_name[abi:cxx11](char const*)' C:/code/NervesOfSteelProject/DatabaseNode/libpqxx/include/pqxx/strconv.hxx:76: undefined reference to pqxx::internal::demangle_type_name[abi:cxx11](char const*)’ C:/code/NervesOfSteelProject/DatabaseNode/libpqxx/include/pqxx/strconv.hxx:76: undefined reference to `pqxx::internal::demangle_type_name[abi:cxx11](char const*)’ collect2.exe: error: ld returned 1 exit status mingw32-make.exe[2]: *** [CMakeFiles\NOSDatabaseProcess.dir\build.make:107: NOSDatabaseProcess.exe] Error 1 mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:95: CMakeFiles/NOSDatabaseProcess.dir/all] Error 2 mingw32-make.exe: *** [Makefile:103: all] Error 2

I am forcing my project to use C++ 17. If I don’t I get a greater amount of errors. Can you help me ? Thanks, Regards

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 40 (21 by maintainers)

Most upvoted comments

Hi, with the changes you proposed in your last comment, I was able to build my code using libpqxx. Also ran the executable produced and it seems to be working fine. I managed to do this from the command line. Through the IDE is another story, I will have to investigate. Thanks for all the help Regards

Same as previous answer: https://github.com/jtv/libpqxx/issues/425#issuecomment-802800664

Do a release build with cmake --build . --config Release and then run cmake --install.

If you are using find_package(), it is recommended to use the CMake target libpqxx::pqxx as a link target rather than lipqxx_LIBRARIES.

Try this change:

project(DatabaseNode)
cmake_minimum_required(VERSION 3.17)
set(CMAKE_CXX_STANDARD 17)

set(PostgreSQL_ROOT C:/Program\ Files/PostgreSQL/13)
find_package(PostgreSQL REQUIRED)

set(libpqxx_ROOT C:/Program\ Files\ (x86)/libpqxx)
find_package(libpqxx REQUIRED)

- include_directories (${PostgreSQL_INCLUDE_DIR} ${libpqxx_ROOT}/include)
- link_directories(${PostgreSQL_LIBRARY_DIR} ${libpqxx_ROOT}/lib)

add_executable(NOSDatabaseProcess NOSDatabaseProcess.cpp)
-target_link_libraries(NOSDatabaseProcess ${lipqxx_LIBRARIES} ${PostgreSQL_LIBRARIES})
+ target_link_libraries(NOSDatabaseProcess lipqxx::pqxx)