Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
daniel-dlds opened this issue Mar 17, 2021 · 40 comments
Closed

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

daniel-dlds opened this issue Mar 17, 2021 · 40 comments

Comments

@daniel-dlds
Copy link

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

@jtv
Copy link
Owner

jtv commented Mar 17, 2021

I'm not the resident CMake expert, but it sounds to me as if perhaps libpqxx didn't actually get built before your code went into the linking phase.

C++17 is correct; that's the oldest version of the language supported by libpqxx 7.x.

@tt4g
Copy link
Contributor

tt4g commented Mar 17, 2021

pqxx::internal::demangle_type_name(char const*) is implemented in src/strconv.cxx, so it should compile if pqxx is installed.

Do you have pqxx installed?
documentation: https://github.com/jtv/libpqxx/blob/7.4.1/BUILDING-cmake.md

@daniel-dlds
Copy link
Author

daniel-dlds commented Mar 17, 2021 via email

@tt4g
Copy link
Contributor

tt4g commented Mar 17, 2021

If copying an installed library, CMake often can't find the library well.
You are using find_library() instead of find_package(), so the CMake target libpqxx::pqxx is not being generated.
In this case, please debug the variables defined by CMake to make sure that the expected library path is detected.

Add message("lipqxx_LIBRARIES=${lipqxx_LIBRARIES}") after find_library(libpqxx REQUIRED) to see what is set in the library path.

+ cmake_minimum_required(VERSION 3.17)
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 ${CMAKE_SOURCE_DIR}/libpqxx)
find_library(libpqxx REQUIRED)

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

+ message("lipqxx_LIBRARIES=${lipqxx_LIBRARIES}")

add_executable(NOSDatabaseProcess NOSDatabaseProcess.cpp)
target_link_libraries(NOSDatabaseProcess ${lipqxx_LIBRARIES}
${PostgreSQL_LIBRARIES})

@daniel-dlds
Copy link
Author

Hi,
After switching to libpqxx 64.5 because of errors on linking with just he include of <libpqxx/libpqxx>, I wrote some calls to the library in my source file. Now it throws more linker errors (below is the start of the linker output) :

====================[ Build | all | Debug ]=====================================
"C:\Program Files\JetBrains\CLion 2020.3.2\bin\cmake\win\bin\cmake.exe" --build C:\code\NervesOfSteelProject\DatabaseNode\cmake-build-debug --target all -- -j 6
-- 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 main': C:/code/NervesOfSteelProject/DatabaseNode/NOSDatabaseProcess.cpp:18: undefined reference to pqxx::transaction_base::commit()'
CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj): In function `pqxx::connection_base::connection_base(pqxx::connectionpolicy&)':

So I tried to build the library on my Windows 10 machine from the command line with admin privileges (because of the install step). Here's the output from the build and install commands (I commented the test cases subdir because It was throwing errors on the build phase) :

C:\devtools\libpqxx-6.4.5>cmake --build .
Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Checking Build System
Building Custom Rule C:/devtools/libpqxx-6.4.5/src/CMakeLists.txt
array.cxx
binarystring.cxx
connection.cxx
connection_base.cxx
cursor.cxx
dbtransaction.cxx
encodings.cxx
errorhandler.cxx
except.cxx
field.cxx
C:\devtools\libpqxx-6.4.5\src\field.cxx(64,38): warning C4267: 'argument': conversion from 'size_t' to 'pqxx::result::s
ize_type', possible loss of data [C:\devtools\libpqxx-6.4.5\src\pqxx_shared.vcxproj]
C:\devtools\libpqxx-6.4.5\src\field.cxx(70,41): warning C4267: 'argument': conversion from 'size_t' to 'pqxx::result::s
ize_type', possible loss of data [C:\devtools\libpqxx-6.4.5\src\pqxx_shared.vcxproj]
C:\devtools\libpqxx-6.4.5\src\field.cxx(76,40): warning C4267: 'argument': conversion from 'size_t' to 'pqxx::result::s
ize_type', possible loss of data [C:\devtools\libpqxx-6.4.5\src\pqxx_shared.vcxproj]
largeobject.cxx
nontransaction.cxx
notification.cxx
pipeline.cxx
prepared_statement.cxx
result.cxx
robusttransaction.cxx
row.cxx
sql_cursor.cxx
statement_parameters.cxx
Generating Code...
Compiling...
strconv.cxx
stream_base.cxx
stream_from.cxx
stream_to.cxx
subtransaction.cxx
tablereader.cxx
tablestream.cxx
tablewriter.cxx
transaction.cxx
transaction_base.cxx
util.cxx
version.cxx
libpqxx.cxx
Generating Code...
Creating library C:/devtools/libpqxx-6.4.5/src/Debug/pqxx.lib and object C:/devtools/libpqxx-6.4.5/src/Debug/pqxx.
exp
pqxx_shared.vcxproj -> C:\devtools\libpqxx-6.4.5\src\Debug\pqxx.dll
Building Custom Rule C:/devtools/libpqxx-6.4.5/src/CMakeLists.txt
array.cxx
binarystring.cxx
connection.cxx
connection_base.cxx
cursor.cxx
dbtransaction.cxx
encodings.cxx
errorhandler.cxx
except.cxx
field.cxx
C:\devtools\libpqxx-6.4.5\src\field.cxx(64,38): warning C4267: 'argument': conversion from 'size_t' to 'pqxx::result::s
ize_type', possible loss of data [C:\devtools\libpqxx-6.4.5\src\pqxx_static.vcxproj]
C:\devtools\libpqxx-6.4.5\src\field.cxx(70,41): warning C4267: 'argument': conversion from 'size_t' to 'pqxx::result::s
ize_type', possible loss of data [C:\devtools\libpqxx-6.4.5\src\pqxx_static.vcxproj]
C:\devtools\libpqxx-6.4.5\src\field.cxx(76,40): warning C4267: 'argument': conversion from 'size_t' to 'pqxx::result::s
ize_type', possible loss of data [C:\devtools\libpqxx-6.4.5\src\pqxx_static.vcxproj]
largeobject.cxx
nontransaction.cxx
notification.cxx
pipeline.cxx
prepared_statement.cxx
result.cxx
robusttransaction.cxx
row.cxx
sql_cursor.cxx
statement_parameters.cxx
Generating Code...
Compiling...
strconv.cxx
stream_base.cxx
stream_from.cxx
stream_to.cxx
subtransaction.cxx
tablereader.cxx
tablestream.cxx
tablewriter.cxx
transaction.cxx
transaction_base.cxx
util.cxx
version.cxx
Generating Code...
pqxx_static.vcxproj -> C:\devtools\libpqxx-6.4.5\src\Debug\pqxx.lib
Building Custom Rule C:/devtools/libpqxx-6.4.5/CMakeLists.txt

C:\devtools\libpqxx-6.4.5>cmake --install .
-- Install configuration: "Release"
-- Up-to-date: C:/Program Files (x86)/libpqxx/lib/cmake/libpqxx/libpqxx-config.cmake
-- Up-to-date: C:/Program Files (x86)/libpqxx/lib/cmake/libpqxx/libpqxx-config-version.cmake
-- Up-to-date: C:/Program Files (x86)/libpqxx/lib/cmake/libpqxx/libpqxx-targets.cmake
-- Installing: C:/Program Files (x86)/libpqxx/lib/cmake/libpqxx/libpqxx-targets-release.cmake
CMake Error at src/cmake_install.cmake:51 (file):
file INSTALL cannot find "C:/devtools/libpqxx-6.4.5/src/Release/pqxx.dll":
No error.
Call Stack (most recent call first):
cmake_install.cmake:72 (include)

So the Install phase threw an error. Do you know what might be the cause ?
Thanks,
Regards

@tt4g
Copy link
Contributor

tt4g commented Mar 19, 2021

Creating library C:/devtools/libpqxx-6.4.5/src/Debug/pqxx.lib and object C:/devtools/libpqxx-6.4.5/src/Debug/pqxx.exp
pqxx_shared.vcxproj -> C:\devtools\libpqxx-6.4.5\src\Debug\pqxx.dll

You did not specify CMAKE_BUILD_TYPE for the cmake command.
The Visual Studio compiler is building the library in Debug mode.

See: https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html

CMake Error at src/cmake_install.cmake:51 (file):
file INSTALL cannot find "C:/devtools/libpqxx-6.4.5/src/Release/pqxx.dll":

However, cmake install will try to install libraries generated in Release mode.
You have not done a Release build, so the library will not be found.

Run cmake --build . --config Release to do a Release build, and then run cmake install.

@daniel-dlds
Copy link
Author

Hi and thanks for your answer,
That worked. The install step succeeded. I was following your guide in https://github.com/jtv/libpqxx/blob/7.4.1/BUILDING-cmake.md, and because I'm not familiar with cmake I followed it blindly.
Anyway
I am getting the same error when linking my code with libpqxx. The errors are the same. The start of the output is below :

====================[ Build | all | Debug ]=====================================
"C:\Program Files\JetBrains\CLion 2020.3.2\bin\cmake\win\bin\cmake.exe" --build C:\code\NervesOfSteelProject\DatabaseNode\cmake-build-debug --target all -- -j 6
[ 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 main': C:/code/NervesOfSteelProject/DatabaseNode/NOSDatabaseProcess.cpp:18: undefined reference to pqxx::transaction_base::commit()'
CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj): In function pqxx::connection_base::connection_base(pqxx::connectionpolicy&)': C:/PROGRA~2/libpqxx/include/pqxx/connection_base.hxx:762: undefined reference to int pqxx::internal::check_library_version<6, 4>()'
C:/PROGRA2/libpqxx/include/pqxx/connection_base.hxx:765: undefined reference to pqxx::connection_base::clearcaps()' CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj): In function pqxx::connect_direct::connect_direct(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)':
C:/PROGRA
2/libpqxx/include/pqxx/connection.hxx:92: undefined reference to pqxx::connectionpolicy::connectionpolicy(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj): In function pqxx::transaction_base::exec0(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)':
C:/PROGRA~2/libpqxx/include/pqxx/transaction_base.hxx:267: undefined reference to pqxx::transaction_base::exec_n(unsigned long long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj): In function pqxx::connect_direct::connect_direct()':
C:/PROGRA
2/libpqxx/include/pqxx/connection.hxx:87: undefined reference to `pqxx::connectionpolicy::~connectionpolicy()'

My CMakeList.txt is below :

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})

What am I missing ?
Thanks

@tt4g
Copy link
Contributor

tt4g commented Mar 19, 2021

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)

@daniel-dlds
Copy link
Author

Hi,
So now I have this CMakeLists.txt :
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)

add_executable(NOSDatabaseProcess NOSDatabaseProcess.cpp)
target_link_libraries(NOSDatabaseProcess lipqxx::pqxx)

When I reload the configuration I am getting :
"C:\Program Files\JetBrains\CLion 2020.3.2\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\code\NervesOfSteelProject\DatabaseNode
-- Configuring done
CMake Error at CMakeLists.txt:14 (add_executable):
Target "NOSDatabaseProcess" links to target "lipqxx::pqxx" but the target
was not found. Perhaps a find_package() call is missing for an IMPORTED
target, or an ALIAS target is missing?

-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.

[Failed to reload]

Thanks,
Regards

@tt4g
Copy link
Contributor

tt4g commented Mar 19, 2021

Hmm. It is strange that find_package(libpqxx) succeeds, but libpqxx::pqxx is not found.
Try replacing target_link_libraries(NOSDatabaseProcess lipqxx::pqxx) with target_link_libraries(NOSDatabaseProcess lipqxx).

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)

add_executable(NOSDatabaseProcess NOSDatabaseProcess.cpp)
-target_link_libraries(NOSDatabaseProcess lipqxx::pqxx)
+target_link_libraries(NOSDatabaseProcess lipqxx)

if(TARGET target-name)
You can also try debugging with if(TARGET target-name) to see if the CMake target for libpqxx is defined.

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)

+if(TARGET pqxx)
+    message("pqxx defined!")
+endif()
+if(TARGET libpqxx)
+    message("libpqxx defined!")
+endif()

add_executable(NOSDatabaseProcess NOSDatabaseProcess.cpp)
target_link_libraries(NOSDatabaseProcess lipqxx)

@daniel-dlds
Copy link
Author

Hi,
I changed the CMakefile to the second version you placed on your previous reply and the output on building is :
====================[ Build | all | Debug ]=====================================
"C:\Program Files\JetBrains\CLion 2020.3.2\bin\cmake\win\bin\cmake.exe" --build C:\code\NervesOfSteelProject\DatabaseNode\cmake-build-debug --target all -- -j 6
Scanning dependencies of target NOSDatabaseProcess
[ 50%] Building CXX object CMakeFiles/NOSDatabaseProcess.dir/NOSDatabaseProcess.cpp.obj
C:\code\NervesOfSteelProject\DatabaseNode\NOSDatabaseProcess.cpp:7:10: fatal error: pqxx/pqxx: No such file or directory
#include <pqxx/pqxx>
^~~~~~~~~~~
compilation terminated.
mingw32-make.exe[2]: *** [CMakeFiles\NOSDatabaseProcess.dir\build.make:82: CMakeFiles/NOSDatabaseProcess.dir/NOSDatabaseProcess.cpp.obj] Error 1
mingw32-make.exe[1]: *** [CMakeFiles\Makefile2:95: CMakeFiles/NOSDatabaseProcess.dir/all] Error 2
mingw32-make.exe: *** [Makefile:103: all] Error 2~

Now it cant find the headers
Thanks,
Regards

@tt4g
Copy link
Contributor

tt4g commented Mar 21, 2021

The current state is strange because it would normally work if libpqxx::pqxx was specified in target_link_libraries().

Can you provide the contents of libpqxx-targets.cmake?
It should exist in C:/Program Files (x86)/libpqxx/lib/cmake/libpqxx/.
libpqxx-targets-release.cmake
The installation log shows that libpqxx-targets-release.cmake also exists, so please provide the contents of that as well.

@daniel-dlds
Copy link
Author

Hi , and thanks for your reply,
I am attaching the requested files to this message.
libpqxx-targets.cmake.txt
libpqxx-targets-release.cmake.txt

Thanks,
Regards

@tt4g
Copy link
Contributor

tt4g commented Mar 21, 2021

Oh, I understand.
CMake target names are defined in libpqxx::pqxx_shared and libpqxx::pqxx_static.
I don't know why, but the CMake target name turned out to be different from what I expected.
Use libpqxx::pqxx_shared to link with shared libraries, and libpqxx::pqxx_static to link with static libraries.

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)

add_executable(NOSDatabaseProcess NOSDatabaseProcess.cpp)
-target_link_libraries(NOSDatabaseProcess lipqxx::pqxx)
+target_link_libraries(NOSDatabaseProcess libpqxx::pqxx_shared)

@daniel-dlds
Copy link
Author

Hi,
With those changes, I get errors, that It can't find the headers while compiling. If I put the line :
include_directories (${PostgreSQL_INCLUDE_DIR} ${libpqxx_ROOT}/include)
below the find_package(libpqxx REQUIRED) statement I get :

====================[ Build | all | Debug ]=====================================
"C:\Program Files\JetBrains\CLion 2020.3.2\bin\cmake\win\bin\cmake.exe" --build C:\code\NervesOfSteelProject\DatabaseNode\cmake-build-debug --target all -- -j 6
Scanning dependencies of target NOSDatabaseProcess
[ 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 main': C:/code/NervesOfSteelProject/DatabaseNode/NOSDatabaseProcess.cpp:18: undefined reference to pqxx::transaction_base::commit()'
CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj): In function pqxx::connection_base::connection_base(pqxx::connectionpolicy&)': C:/PROGRA~2/libpqxx/include/pqxx/connection_base.hxx:762: undefined reference to int pqxx::internal::check_library_version<6, 4>()'
C:/PROGRA2/libpqxx/include/pqxx/connection_base.hxx:765: undefined reference to pqxx::connection_base::clearcaps()' CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj): In function pqxx::connect_direct::connect_direct(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)':
C:/PROGRA
2/libpqxx/include/pqxx/connection.hxx:92: undefined reference to pqxx::connectionpolicy::connectionpolicy(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj): In function pqxx::transaction_base::exec0(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)':
C:/PROGRA2/libpqxx/include/pqxx/transaction_base.hxx:267: undefined reference to pqxx::transaction_base::exec_n(unsigned long long, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj): In function pqxx::connect_direct::connect_direct()':
C:/PROGRA
2/libpqxx/include/pqxx/connection.hxx:87: undefined reference to pqxx::connectionpolicy::~connectionpolicy()' CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj): In function pqxx::basic_connection_basepqxx::connect_direct::basic_connection_base()':
C:/PROGRA
2/libpqxx/include/pqxx/basic_connection.hxx:70: undefined reference to pqxx::connection_base::close()' CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj): In function pqxx::internal::basic_transaction::basic_transaction()':
C:/PROGRA
2/libpqxx/include/pqxx/transaction.hxx:31: undefined reference to pqxx::dbtransaction::~dbtransaction()' CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj): In function pqxx::transaction<(pqxx::isolation_level)0, (pqxx::readwrite_policy)1>::transaction()':
C:/PROGRA
2/libpqxx/include/pqxx/transaction.hxx:102: undefined reference to pqxx::transaction_base::End()' CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj): In function pqxx::basic_connection_basepqxx::connect_direct::basic_connection_base(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)':
C:/PROGRA
2/libpqxx/include/pqxx/basic_connection.hxx:61: undefined reference to pqxx::connection_base::init()' CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj): In function pqxx::transaction<(pqxx::isolation_level)0, (pqxx::readwrite_policy)1>::transaction(pqxx::connection_base&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)':
C:/PROGRA2/libpqxx/include/pqxx/transaction.hxx:95: undefined reference to pqxx::dbtransaction::fullname(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)' C:/PROGRA~2/libpqxx/include/pqxx/transaction.hxx:95: undefined reference to pqxx::internal::basic_transaction::basic_transaction(pqxx::connection_base&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, pqxx::readwrite_policy)'
C:/PROGRA
2/libpqxx/include/pqxx/transaction.hxx:96: undefined reference to pqxx::transaction_base::Begin()' CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj):NOSDatabaseProcess.cpp:(.rdata$_ZTVN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE[_ZTVN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE]+0x28): undefined reference to pqxx::dbtransaction::do_begin()'
CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj):NOSDatabaseProcess.cpp:(.rdata$_ZTVN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE[_ZTVN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE]+0x30): undefined reference to pqxx::dbtransaction::do_exec(char const*)' CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj):NOSDatabaseProcess.cpp:(.rdata$_ZTVN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE[_ZTVN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE]+0x38): undefined reference to pqxx::internal::basic_transaction::do_commit()'
CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj):NOSDatabaseProcess.cpp:(.rdata$_ZTVN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE[_ZTVN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE]+0x40): undefined reference to pqxx::dbtransaction::do_abort()' CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj):NOSDatabaseProcess.cpp:(.rdata$_ZTCN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE0_NS_8internal17basic_transactionE[_ZTCN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE0_NS_8internal17basic_transactionE]+0x28): undefined reference to pqxx::dbtransaction::do_begin()'
CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj):NOSDatabaseProcess.cpp:(.rdata$_ZTCN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE0_NS_8internal17basic_transactionE[_ZTCN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE0_NS_8internal17basic_transactionE]+0x30): undefined reference to pqxx::dbtransaction::do_exec(char const*)' CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj):NOSDatabaseProcess.cpp:(.rdata$_ZTCN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE0_NS_8internal17basic_transactionE[_ZTCN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE0_NS_8internal17basic_transactionE]+0x38): undefined reference to pqxx::internal::basic_transaction::do_commit()'
CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj):NOSDatabaseProcess.cpp:(.rdata$_ZTCN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE0_NS_8internal17basic_transactionE[_ZTCN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE0_NS_8internal17basic_transactionE]+0x40): undefined reference to pqxx::dbtransaction::do_abort()' CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj):NOSDatabaseProcess.cpp:(.rdata$_ZTCN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE0_NS_13dbtransactionE[_ZTCN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE0_NS_13dbtransactionE]+0x28): undefined reference to pqxx::dbtransaction::do_begin()'
CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj):NOSDatabaseProcess.cpp:(.rdata$_ZTCN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE0_NS_13dbtransactionE[_ZTCN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE0_NS_13dbtransactionE]+0x30): undefined reference to pqxx::dbtransaction::do_exec(char const*)' CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj):NOSDatabaseProcess.cpp:(.rdata$_ZTCN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE0_NS_13dbtransactionE[_ZTCN4pqxx11transactionILNS_15isolation_levelE0ELNS_16readwrite_policyE1EEE0_NS_13dbtransactionE]+0x40): undefined reference to pqxx::dbtransaction::do_abort()'
CMakeFiles\NOSDatabaseProcess.dir/objects.a(NOSDatabaseProcess.cpp.obj):NOSDatabaseProcess.cpp:(.rdata$.refptr._ZTVN4pqxx14connect_directE[.refptr._ZTVN4pqxx14connect_directE]+0x0): undefined reference to `vtable for pqxx::connect_direct'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [CMakeFiles\NOSDatabaseProcess.dir\build.make:108: 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

Hope it helps,
Thanks,
Regards

@tt4g
Copy link
Contributor

tt4g commented Mar 22, 2021

It is strange that I get undefined reference error even though it is installed. Can you check if pqxx.lib is included in the link target of the compile command?
I think the build command is recorded in CMakeError.log.

By the way, you have failed to install pqxx once.
Did you remove the previously installed pqxx dirty files once before reinstalling?
If not, the failed installation files may still be there and causing the problem.

@tt4g
Copy link
Contributor

tt4g commented Mar 22, 2021

OK, I checked libpqxx-targets.cmake again.
libpqxx::pqxx_shared is defined, but doesn't appear to be built (which is odd, but could be a result of a failed install the first time).
This means that you can only specify libpqxx::pqxx_static (static library) as a link target.

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)

add_executable(NOSDatabaseProcess NOSDatabaseProcess.cpp)
-target_link_libraries(NOSDatabaseProcess libpqxx::pqxx_shared)
+target_link_libraries(NOSDatabaseProcess libpqxx::pqxx_static)

NOTE include_directories (${PostgreSQL_INCLUDE_DIR} ${libpqxx_ROOT}/include) should no longer be needed.

If you need shared libraries, run the cmake-configuration step with cmake -DBUILD_SHARED_LIBS=ON and then cmake --build . --config Release and cmake --install ..

@jtv
Copy link
Owner

jtv commented Mar 22, 2021

By the way @daniel-dlds rememer to use triple backticks around multi-line literal blocks, such as code or compiler output. For some reason this is going wrong for a lot of people lately.

@daniel-dlds
Copy link
Author

daniel-dlds commented Mar 24, 2021

Hi,
I did a C:\devtools\libpqxx-6.4.5>cmake --build . --target clean on the root directory of the project libpqxx.
The output was :

Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.


I then did a :
cmake -DBUILD_SHARED_LIBS=ON
And then a :
cmake --build . --config Release
And then a :
cmake --install .
The output of the install reported all files as 'Up-to-date'

Then went on to build my project. I don't get the compilation errors of the missing includes, it appears it can find them now.
Linking with the line :
target_link_libraries(NOSDatabaseProcess libpqxx::pqxx_static)
or the line :
target_link_libraries(NOSDatabaseProcess libpqxx::pqxx_shared)
gives me the linker errors that I posted in a previous comment.

Thanks,
Regards

@tt4g
Copy link
Contributor

tt4g commented Mar 24, 2021

As far as I know, cmake --build . --target clean with when the Visual Studio IDE does not working.
Did you run the uninstall correctly?

Official FAQ: https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake

And we can't tell anything from the error information provided.
Please try the following steps.

  1. Make sure you uninstall the pqxx that is currently installed (Remove C:/Program Files (x86)/libpqxx).
  2. Delete the pqxx directory where you have been working on the build. (CMake generates a build cache, so using the same working directory may cause problems).
  3. Download the pqxx source and install it with CMake.
  4. Build your project. Don't forget to delete the CMake cache at this time.
    NOTE As long as the cache is not deleted, CMake will continue to refer to the old information.

If it still doesn't work, please provide pqxx-targets.cmake again.

@daniel-dlds
Copy link
Author

daniel-dlds commented Mar 24, 2021

Hi,
To remove the previous installation of version 6.4.5 I just deleted the folder under "Program Files(x86).
Then I deleted the folder with the distribution and unzipped it again to the same place.
Then with a command window with admin privileges I found out I had to do a :
cmake --configure .
Because otherwise it would throw the error CMake Error : could not load cache
Then I did a :
cmake --build .
When building the tests it throws a lot of warnings and errors like below :

pqxx.lib(connection_base.obj) : error LNK2019: unresolved external symbol PQputCopyData referenced in function "private
: void __cdecl pqxx::connection_base::write_copy_line(class std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > const &)" (?write_copy_line@connection_base@pqxx@@AEAAXAEBV?$basic_string@DU?$char_traits@D@std@
@V?$allocator@D@2@@std@@@Z) [C:\devtools\libpqxx-6.4.5\test\unit\unit_runner.vcxproj]

I guess it expects me to have visual studio.
Anyway I try to install it doing a :

cmake --install .
-- Install configuration: "Release"
-- Installing: C:/Program Files (x86)/libpqxx/lib/cmake/libpqxx/libpqxx-config.cmake
-- Installing: C:/Program Files (x86)/libpqxx/lib/cmake/libpqxx/libpqxx-config-version.cmake
-- Installing: C:/Program Files (x86)/libpqxx/lib/cmake/libpqxx/libpqxx-targets.cmake
-- Installing: C:/Program Files (x86)/libpqxx/lib/cmake/libpqxx/libpqxx-targets-release.cmake
CMake Error at src/cmake_install.cmake:51 (file):
  file INSTALL cannot find "C:/devtools/libpqxx-6.4.5/src/Release/pqxx.dll":
  File exists.
Call Stack (most recent call first):
  cmake_install.cmake:72 (include)

So It didn't install anything. Note that my previous installation that I erased before all this was done with autotools on cygwin.
This time I tried the CMake way because the project I am trying to use this also uses CMake.

Thanks,
Regards

@tt4g
Copy link
Contributor

tt4g commented Mar 24, 2021

When building the tests it throws a lot of warnings and errors like below:

pqxx.lib(connection_base.obj) : error LNK2019: unresolved external symbol PQputCopyData referenced in function "private
: void __cdecl pqxx::connection_base::write_copy_line(class std::basic_string<char,struct std::char_traits<char>,class
std::allocator<char> > const &)" (?write_copy_line@connection_base@pqxx@@AEAAXAEBV?$basic_string@DU?$char_traits@D@std@
@V?$allocator@D@2@@std@@@Z) [C:\devtools\libpqxx-6.4.5\test\unit\unit_runner.vcxproj]

The reason is that PostgreSQL cannot be found.

So It didn't install anything. Note that my previous installation that I erased before all this was done with autotools on cygwin.

Are you building your project with cygwin?
You wrote 7 days ago that you were using cygwin, but the recent CMake logs show that pqxx was built in Visual Studio.
pqxx built by Visual Studio should not be available on cygwin.
If you want to build your project with cygwin, then you must also build pqxx with cygwin.

@daniel-dlds
Copy link
Author

daniel-dlds commented Mar 24, 2021 via email

@tt4g
Copy link
Contributor

tt4g commented Mar 24, 2021

CMake uses environment variables and other information to determine which compiler and building platoform to use.
From the build messages of pqxx, it looks like you are using Visual Studio, so try to specify the generator with the cmake --configure command.

On cygwin you should use Make generator.
Example: cmake --configure . -G "Unix Makefiles"

Look: https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html
and see: https://stackoverflow.com/questions/25941536/what-is-a-cmake-generator

The binary produced by gcc compiler is not compatible with Windows binaries and ABI (Application Binary Interface).
So if you are installing PostgreSQL with the Windows installer, you will get a link error due to ABI compatibility problems.
You will have to install the PostgreSQL library for cygwin.

@daniel-dlds
Copy link
Author

daniel-dlds commented Mar 25, 2021

Hi,
I want to use the Visual studio compiler. Here is the output of the configure step done on a fresh checkout of the project :

C:\devtools\libpqxx-6.4.5>cmake --configure .
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.18363.
-- The CXX compiler identification is MSVC 19.28.29912.0
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PostgreSQL: C:/Program Files/PostgreSQL/13/lib/libpq.lib (found version "13.2")
-- Looking for C++ include sys/select.h
-- Looking for C++ include sys/select.h - not found
-- Looking for C++ include sys/time.h
-- Looking for C++ include sys/time.h - not found
-- Looking for C++ include sys/types.h
-- Looking for C++ include sys/types.h - found
-- Looking for C++ include unistd.h
-- Looking for C++ include unistd.h - not found
-- Looking for poll
-- Looking for poll - not found
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting std::optional
-- Detecting std::optional - not supported
-- Detecting std::experimental::optional
-- Detecting std::experimental::optional - not supported
-- Detecting __attribute__ ((const))
-- Detecting __attribute__ ((const)) - not supported
-- Detecting __attribute__ ((pure))
-- Detecting __attribute__ ((pure)) - not supported
-- Detecting __attribute__ ((visibility))
-- Detecting __attribute__ ((visibility)) - not supported
-- Generating config.h
-- Generating config.h - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/devtools/libpqxx-6.4.5

I have put the following on the CmakeLists.txt before executing the above command:

find_package(PostgreSQL REQUIRED)

I think that it is finding Postgres and Visual Studio compiler,
It only throws errors when compiling tests. I removed that subdirectory to allow it to go to the end.
When I install, the install process is trying to find the build products under "Release", but the build was made in "Debug"

#if (BUILD_TEST)
#  add_subdirectory(test)
#endif ()

During the execution of the build command the output is :

C:\devtools\libpqxx-6.4.5>cmake --build .
CMake is re-running because C:/devtools/libpqxx-6.4.5/CMakeFiles/generate.stamp is out-of-date.
  the file 'C:/devtools/libpqxx-6.4.5/CMakeLists.txt'
  is newer than 'C:/devtools/libpqxx-6.4.5/CMakeFiles/generate.stamp.depend'
  result='-1'
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.18363.
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Detecting std::optional
-- Detecting std::optional - not supported
-- Detecting std::experimental::optional
-- Detecting std::experimental::optional - not supported
-- Detecting __attribute__ ((const))
-- Detecting __attribute__ ((const)) - not supported
-- Detecting __attribute__ ((pure))
-- Detecting __attribute__ ((pure)) - not supported
-- Detecting __attribute__ ((visibility))
-- Detecting __attribute__ ((visibility)) - not supported
-- Generating config.h
-- Generating config.h - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/devtools/libpqxx-6.4.5
Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

  Checking Build System
  Building Custom Rule C:/devtools/libpqxx-6.4.5/src/CMakeLists.txt
  array.cxx
  binarystring.cxx
  connection.cxx
  connection_base.cxx
  cursor.cxx
  dbtransaction.cxx
  encodings.cxx
  errorhandler.cxx
  except.cxx
  field.cxx
C:\devtools\libpqxx-6.4.5\src\field.cxx(64,38): warning C4267: 'argument': conversion from 'size_t' to 'pqxx::result::s
ize_type', possible loss of data [C:\devtools\libpqxx-6.4.5\src\pqxx_shared.vcxproj]
C:\devtools\libpqxx-6.4.5\src\field.cxx(70,41): warning C4267: 'argument': conversion from 'size_t' to 'pqxx::result::s
ize_type', possible loss of data [C:\devtools\libpqxx-6.4.5\src\pqxx_shared.vcxproj]
C:\devtools\libpqxx-6.4.5\src\field.cxx(76,40): warning C4267: 'argument': conversion from 'size_t' to 'pqxx::result::s
ize_type', possible loss of data [C:\devtools\libpqxx-6.4.5\src\pqxx_shared.vcxproj]
  largeobject.cxx
  nontransaction.cxx
  notification.cxx
  pipeline.cxx
  prepared_statement.cxx
  result.cxx
  robusttransaction.cxx
  row.cxx
  sql_cursor.cxx
  statement_parameters.cxx
  Generating Code...
  Compiling...
  strconv.cxx
  stream_base.cxx
  stream_from.cxx
  stream_to.cxx
  subtransaction.cxx
  tablereader.cxx
  tablestream.cxx
  tablewriter.cxx
  transaction.cxx
  transaction_base.cxx
  util.cxx
  version.cxx
  libpqxx.cxx
  Generating Code...
     Creating library C:/devtools/libpqxx-6.4.5/src/Debug/pqxx.lib and object C:/devtools/libpqxx-6.4.5/src/Debug/pqxx.
  exp
  pqxx_shared.vcxproj -> C:\devtools\libpqxx-6.4.5\src\Debug\pqxx.dll
  Building Custom Rule C:/devtools/libpqxx-6.4.5/src/CMakeLists.txt
  array.cxx
  binarystring.cxx
  connection.cxx
  connection_base.cxx
  cursor.cxx
  dbtransaction.cxx
  encodings.cxx
  errorhandler.cxx
  except.cxx
  field.cxx
C:\devtools\libpqxx-6.4.5\src\field.cxx(64,38): warning C4267: 'argument': conversion from 'size_t' to 'pqxx::result::s
ize_type', possible loss of data [C:\devtools\libpqxx-6.4.5\src\pqxx_static.vcxproj]
C:\devtools\libpqxx-6.4.5\src\field.cxx(70,41): warning C4267: 'argument': conversion from 'size_t' to 'pqxx::result::s
ize_type', possible loss of data [C:\devtools\libpqxx-6.4.5\src\pqxx_static.vcxproj]
C:\devtools\libpqxx-6.4.5\src\field.cxx(76,40): warning C4267: 'argument': conversion from 'size_t' to 'pqxx::result::s
ize_type', possible loss of data [C:\devtools\libpqxx-6.4.5\src\pqxx_static.vcxproj]
  largeobject.cxx
  nontransaction.cxx
  notification.cxx
  pipeline.cxx
  prepared_statement.cxx
  result.cxx
  robusttransaction.cxx
  row.cxx
  sql_cursor.cxx
  statement_parameters.cxx
  Generating Code...
  Compiling...
  strconv.cxx
  stream_base.cxx
  stream_from.cxx
  stream_to.cxx
  subtransaction.cxx
  tablereader.cxx
  tablestream.cxx
  tablewriter.cxx
  transaction.cxx
  transaction_base.cxx
  util.cxx
  version.cxx
  Generating Code...
  pqxx_static.vcxproj -> C:\devtools\libpqxx-6.4.5\src\Debug\pqxx.lib
  Building Custom Rule C:/devtools/libpqxx-6.4.5/CMakeLists.txt

Then the install command :

C:\devtools\libpqxx-6.4.5>cmake --install .
-- Install configuration: "Release"
-- Up-to-date: C:/Program Files (x86)/libpqxx/lib/cmake/libpqxx/libpqxx-config.cmake
-- Installing: C:/Program Files (x86)/libpqxx/lib/cmake/libpqxx/libpqxx-config-version.cmake
-- Installing: C:/Program Files (x86)/libpqxx/lib/cmake/libpqxx/libpqxx-targets.cmake
-- Installing: C:/Program Files (x86)/libpqxx/lib/cmake/libpqxx/libpqxx-targets-release.cmake
CMake Error at src/cmake_install.cmake:51 (file):
  file INSTALL cannot find "C:/devtools/libpqxx-6.4.5/src/Release/pqxx.dll":
  No error.
Call Stack (most recent call first):
  cmake_install.cmake:72 (include)

Thanks,
Regards

@tt4g
Copy link
Contributor

tt4g commented Mar 25, 2021

Same as previous answer: #425 (comment)

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

@daniel-dlds
Copy link
Author

daniel-dlds commented Mar 25, 2021

Hi,
I did what you suggested. The files went into :

C:/Program Files (x86)/libpqxx

Now when I run CMake on my project it says :

Could not find a configuration file for package "libpqxx" that is
  compatible with requested version "".

The following configuration files were considered but not accepted:

C:/Program Files (x86)/libpqxx/lib/cmake/libpqxx/libpqxx-config.cmake, version: 6.4.5 (64bit)

If I put the version in the find_package statement :

CMake Error at CMakeLists.txt:9 (find_package):
  Could not find a configuration file for package "libpqxx" that is
  compatible with requested version "6.4.5".

  The following configuration files were considered but not accepted:

    C:/Program Files (x86)/libpqxx/lib/cmake/libpqxx/libpqxx-config.cmake, version: 6.4.5 (64bit)

Thanks for you time and patience,
Regards

@daniel-dlds
Copy link
Author

daniel-dlds commented Mar 25, 2021

Hi,
I just noticed that my IDE (CLion) is building for x86 which I think its 32 bit. Maybe that could be a problem ?
CMake reports the library being 64 bit.
Thanks,
Regards

@tt4g
Copy link
Contributor

tt4g commented Mar 25, 2021

If I put the version in the find_package statement :

Please, provide your project's CMakeLists.txt.

I just noticed that my IDE (CLion) is building for x86 which I think its 32 bit. Maybe that could be a problem ?
CMake reports the library being 64 bit.

64bit is better.

@daniel-dlds
Copy link
Author

Hi,
Below is the CMakeLists.txt

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)

find_package(libpqxx 6.4.5 REQUIRED)

add_executable(NOSDatabaseProcess NOSDatabaseProcess.cpp)
target_link_libraries(NOSDatabaseProcess libpqxx libpq)

Thanks,
Regards

@tt4g
Copy link
Contributor

tt4g commented Mar 25, 2021

The configuration does not seem to be wrong. It may be that the version information is not recorded in libpqxx-config-version.cmake.

Replace find_package(libpqxx 6.4.5 REQUIRED) with find_package(libpqxx REQUIRED) for working build process.

@daniel-dlds
Copy link
Author

daniel-dlds commented Mar 26, 2021

Hi,
Without the version information :

"C:\Program Files\JetBrains\CLion 2020.3.2\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=RelWithDebInfo -m64 -G "CodeBlocks - NMake Makefiles" C:\code\NervesOfSteelProject\DatabaseNode
CMake Error at CMakeLists.txt:9 (find_package):
  Could not find a configuration file for package "libpqxx" that is
  compatible with requested version "".

  The following configuration files were considered but not accepted:

    C:/Program Files (x86)/libpqxx/lib/cmake/libpqxx/libpqxx-config.cmake, version: 6.4.5 (64bit)



-- Configuring incomplete, errors occurred!
See also "C:/code/NervesOfSteelProject/DatabaseNode/cmake-build-relwithdebinfo-visual-studio/CMakeFiles/CMakeOutput.log".

[Finished]

Thanks,
Regards

@tt4g
Copy link
Contributor

tt4g commented Mar 26, 2021

Looking at the previous comments, that error was not reported.
The installation has failed once with this comment.
Note that C:/Program Files (x86)/libpqxx is still created even though the installation process has failed: #425 (comment)

Uninstall pqxx and then do a clean install with cmake --configure . -DCMAKE_BUILD_TYPE=Release, cmake --build . --config Release and cmake --install

@daniel-dlds
Copy link
Author

Hi,

I followed your instructions exactly on a windows command prompt with admin privileges. It built the software only throwing some errors on the test build phase. It installed the software in c:\Program Files(x86)\libpqxx.

I then switched to my IDE (CLion), and reloaded the cMake profile. It refuses to reload with the same error :

"C:\Program Files\JetBrains\CLion 2020.3.2\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=RelWithDebInfo -m64 -G "CodeBlocks - NMake Makefiles" C:\code\NervesOfSteelProject\DatabaseNode
CMake Error at CMakeLists.txt:9 (find_package):
  Could not find a configuration file for package "libpqxx" that is
  compatible with requested version "".

  The following configuration files were considered but not accepted:

    C:/Program Files (x86)/libpqxx/lib/cmake/libpqxx/libpqxx-config.cmake, version: 6.4.5 (64bit)



-- Configuring incomplete, errors occurred!
See also "C:/code/NervesOfSteelProject/DatabaseNode/cmake-build-relwithdebinfo-visual-studio/CMakeFiles/CMakeOutput.log".

[Finished]

I then tried building from the cmd line. Below is what I tried and the result :

C:\code\NervesOfSteelProject\DatabaseNode>cmake --configure . -DCMAKE_BUILD_TYPE=Release
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.18363.
-- The C compiler identification is MSVC 19.28.29912.0
-- The CXX compiler identification is MSVC 19.28.29912.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PostgreSQL: C:/Program Files/PostgreSQL/13/lib/libpq.lib (found version "13.2")
-- Configuring done
-- Generating done
-- Build files have been written to: C:/code/NervesOfSteelProject/DatabaseNode

C:\code\NervesOfSteelProject\DatabaseNode>cmake --build . --config Release
Microsoft (R) Build Engine version 16.9.0+57a23d249 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

  Checking Build System
  Building Custom Rule C:/code/NervesOfSteelProject/DatabaseNode/CMakeLists.txt
  NOSDatabaseProcess.cpp
C:\code\NervesOfSteelProject\DatabaseNode\NOSDatabaseProcess.cpp(7,10): fatal error C1083: Cannot open include file: 'pqxx/pqxx': No such file or
 directory [C:\code\NervesOfSteelProject\DatabaseNode\NOSDatabaseProcess.vcxproj]

C:\code\NervesOfSteelProject\DatabaseNode>

Thanks,
Regards

@tt4g
Copy link
Contributor

tt4g commented Mar 28, 2021

Errors reported in CLion are considered to be CLion problems.
I assume you have not deleted the CMake cache for the project you are building in the CLion after reinstalling pqxx.

I then tried building from the cmd line. Below is what I tried and the result :

You seem to be making the same mistakes as before.

Replace libpqxx of target_link_libraries(NOSDatabaseProcess libpqxx libpq) with libpqxx::pqxx_shared or libpqxx::pqxx_static.

@daniel-dlds
Copy link
Author

daniel-dlds commented Mar 29, 2021

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

@daniel-dlds
Copy link
Author

daniel-dlds commented Mar 29, 2021

Hi,
One thing I noticed. My code only links with the same cmake config as of the libpqxx. I had to build my project in Release in order to link to your library. Can this be modified ? I want your library on release config, but compile my code in Debug.
I am statically linking the library.
EDIT: tried compiling libpqxx in Debug. it compiled but the installation comand looked for the DLL under the Release folder and could not find, so the installation stopped there

Seems that now I can only use your library, if I compile for a Release mode, so I won't be able to debug my code, right ?

Thanks,
Regards

@tt4g
Copy link
Contributor

tt4g commented Mar 29, 2021

You may be able to install the Debug library with the following command.
Don't forget to uninstall the pqxx you have already installed first.

$ cmake -DCMAKE_BUILD_TYPE=Debug --configure .
$ cmake --build . --config Debug
$ cmake --install

However, since debug builds are not usually installed on the system, the installation may fail.

@jtv
Copy link
Owner

jtv commented Mar 29, 2021

@daniel-dlds The details may differ per compiler, but generally: If you build your application as Release, you must also build libpqxx as Release. If you build your application as Debug, you must also build libpqxx as Debug.

The reason as I understand it is that "Debug" compilations often add instrumentation in types like std::string etc. to check for bugs. The instrumentation makes the type incompatible with the "regular" version.

@daniel-dlds
Copy link
Author

Hi,
I managed to install the lib from a debug build by fooling the install script. I copied the Debug folder to another called Release, and the installation was done. I did this for the makefile of my project can call find_package(libpqxx REQUIRED).

I now can build my project in Debug having the library compiled in Debug installed as if it were release..
All this is in the command line. As to CLion, it still does not work for some other configuration reason.
For me it's fine as it is.

Thanks a lot for your assistance. I am a noob in CMake and C++ development in general.
Regards

@jtv jtv closed this as completed May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants