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
Comments
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. |
Do you have pqxx installed? |
Hi, and thanks for your reply,
I got the sources and used autotools to build libpqxx on cygwin. It went
fine. Then I followed the instructions on :
Building and Using DLLs (cygwin.com)
<https://cygwin.com/cygwin-ug-net/dll.html>
To build the DLL version. then I copied the DLL and the headers in the
include directory to a folder under my project. then did the following
CMake configuration in the CMakeFile :
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)
add_executable(NOSDatabaseProcess NOSDatabaseProcess.cpp)
target_link_libraries(NOSDatabaseProcess ${lipqxx_LIBRARIES}
${PostgreSQL_LIBRARIES})
So I guess it's trying to link, and it does so partially.
Anyway, I did the same with the latest 6.xx version of libpqxx and I can
link that one (because it is compatible with C++11)
Thanks,
Regards
…On Wed, Mar 17, 2021 at 2:21 PM tt4g ***@***.***> wrote:
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
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#425 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABCEAHJ34SOFER7J57ILMADTEC3GJANCNFSM4ZKMXETA>
.
|
If copying an installed library, CMake often can't find the library well. Add + 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})
|
Hi, ====================[ Build | all | Debug ]===================================== 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 . Checking Build System C:\devtools\libpqxx-6.4.5>cmake --install . So the Install phase threw an error. Do you know what might be the cause ? |
You did not specify See: https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html
However, Run |
Hi and thanks for your answer, ====================[ Build | all | Debug ]===================================== My CMakeList.txt is below : project(DatabaseNode) set(PostgreSQL_ROOT C:/Program\ Files/PostgreSQL/13) set(libpqxx_ROOT C:/Program\ Files\ (x86)/libpqxx) include_directories (${PostgreSQL_INCLUDE_DIR} ${libpqxx_ROOT}/include) add_executable(NOSDatabaseProcess NOSDatabaseProcess.cpp) What am I missing ? |
If you are using 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) |
Hi, set(PostgreSQL_ROOT C:/Program\ Files/PostgreSQL/13) set(libpqxx_ROOT C:/Program\ Files\ (x86)/libpqxx) add_executable(NOSDatabaseProcess NOSDatabaseProcess.cpp) When I reload the configuration I am getting : -- Generating done [Failed to reload] Thanks, |
Hmm. It is strange that 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)
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) |
Hi, Now it cant find the headers |
The current state is strange because it would normally work if Can you provide the contents of |
Hi , and thanks for your reply, Thanks, |
Oh, I understand. 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) |
Hi, ====================[ Build | all | Debug ]===================================== Hope it helps, |
It is strange that I get undefined reference error even though it is installed. Can you check if By the way, you have failed to install pqxx once. |
OK, I checked 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 If you need shared libraries, run the cmake-configuration step with |
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. |
Hi,
I then did a : 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. Thanks, |
As far as I know, 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.
If it still doesn't work, please provide |
Hi,
I guess it expects me to have visual studio.
So It didn't install anything. Note that my previous installation that I erased before all this was done with autotools on cygwin. Thanks, |
The reason is that PostgreSQL cannot be found.
Are you building your project with cygwin? |
Hi and thanks for your reply,
At first I tried building with CMake. But because I was not getting it to
build because the result was the same as the one I described in my previous
post, I tried going the Cygwin route.
And was able to build it. The configure script was able to find PostgreSQL
and I built and installed it. Then I started trying to include it in my
project.
It was then that created this ticket. Now I am trying to go the CMake way,
because the project I am developing is in CMake. I am on Windows 10.
Thanks,
Regards
…On Wed, Mar 24, 2021 at 8:57 PM tt4g ***@***.***> wrote:
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 &)" ***@***.******@***.***@@***@***.***?$char_traits@***@***.***@
@v?$allocator@***@***.***@@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.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#425 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABCEAHLHNIDMVAYZILW5ENDTFJG3VANCNFSM4ZKMXETA>
.
|
CMake uses environment variables and other information to determine which compiler and building platoform to use. On cygwin you should use Make generator. Look: https://cmake.org/cmake/help/latest/manual/cmake-generators.7.html The binary produced by gcc compiler is not compatible with Windows binaries and ABI (Application Binary Interface). |
Hi,
I have put the following on the CmakeLists.txt before executing the above command:
I think that it is finding Postgres and Visual Studio compiler,
During the execution of the build command the output is :
Then the install command :
Thanks, |
Same as previous answer: #425 (comment) Do a release build with |
Hi,
Now when I run CMake on my project it says :
If I put the version in the find_package statement :
Thanks for you time and patience, |
Hi, |
Please, provide your project's
64bit is better. |
Hi,
Thanks, |
The configuration does not seem to be wrong. It may be that the version information is not recorded in Replace |
Hi,
Thanks, |
Looking at the previous comments, that error was not reported. Uninstall pqxx and then do a clean install with |
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 I then switched to my IDE (CLion), and reloaded the cMake profile. It refuses to reload with the same error :
I then tried building from the cmd line. Below is what I tried and the result :
Thanks, |
Errors reported in CLion are considered to be CLion problems.
You seem to be making the same mistakes as before. Replace |
Hi, |
Hi, 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, |
You may be able to install the Debug library with the following command. $ 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. |
@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 |
Hi, I now can build my project in Debug having the library compiled in Debug installed as if it were release.. Thanks a lot for your assistance. I am a noob in CMake and C++ development in general. |
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
The text was updated successfully, but these errors were encountered: