0

I'm rying to setup a CMake project under windows 10 using PostgreSQL.

When I try to find_package

find_package(PostgreSQL REQUIRED)

I get the following error

  Could NOT find PostgreSQL (missing: PostgreSQL_LIBRARY) (found version
  "10.4")
Call Stack (most recent call first):
  C:/Program Files/CMake/share/cmake-3.8/Modules/FindPackageHandleStandardArgs.cmake:377 (_FPHSA_FAILURE_MESSAGE)
  C:/Program Files/CMake/share/cmake-3.8/Modules/FindPostgreSQL.cmake:175 (find_package_handle_standard_args)
  server/CMakeLists.txt:13 (find_package)

It seems like it has found "10.4" version but it's missing the PostgreSQL_LIBRARY.

How can I fix that?

kometen
  • 6,536
  • 6
  • 41
  • 51
tuket
  • 3,232
  • 1
  • 26
  • 41
  • I recall I had some issues when using libpq a while back on FreeBSD. The stock pkg-libpq is using Postgres ver. 9, where as I was running 10. Could it be a mismatch between this? What OS are you running? Windows? – kometen Aug 04 '18 at 21:09
  • Yes, it's Windows 10 – tuket Aug 04 '18 at 21:38
  • Like any dependency discovered with `find_package()`, add absolute path of libpq install root folder to `CMAKE_PREFIX_PATH` when you call CMake configuration. – SpacePotatoes Apr 18 '22 at 13:50

5 Answers5

1

I had the same goal - trying to use PostgreSQL libpq on Windows 10 in a CMake project, and I had the same error. Following on from Mike's reply I added set(PostgreSQL_ADDITIONAL_VERSIONS "14") before the call to find_package(PostgreSQL REQUIRED) and can confirm this fixed the problem. Just confirming that Mike's solution worked for me.

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31555774) – wohlstad Apr 17 '22 at 14:39
  • Hi wohlstad, can you help my understand your feedback? I think the answer to kohmens question is to add "set(PostgreSQL_ADDITIONAL_VERSIONS "10")" before find_package(PostgreSQL REQUIRED) for their situation (as alluded to by Mike). Should my answer be "add set(PostgreSQL_ADDITIONAL_VERSIONS "10") before find_package(PostgreSQL REQUIRED) in your CMake project" ? – davidxmiller Apr 18 '22 at 16:53
  • Confirming that another answer works should not be posted as a new answer, but rather as a comment. See this guide about answers on SO: https://stackoverflow.com/help/how-to-answer – wohlstad Apr 19 '22 at 03:25
  • Aha, thank you. I can't post (50 reputation) a comment on Mike's answer. – davidxmiller Apr 21 '22 at 17:51
0

My FindPostgreSQL.cmake has this note:

# Note:
# PostgreSQL_ADDITIONAL_VERSIONS is a variable that can be used to set the
# version number of the implementation of PostgreSQL.
# In Windows the default installation of PostgreSQL uses that as part of the path.
# E.g C:\Program Files\PostgreSQL\8.4.
# Currently, the following version numbers are known to this module:
# "10" "9.6" "9.5" "9.4" "9.3" "9.2" "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0"
#
# To use this variable just do something like this:
# set(PostgreSQL_ADDITIONAL_VERSIONS "9.2" "8.4.4")
# before calling find_package(PostgreSQL) in your CMakeLists.txt file.
# This will mean that the versions you set here will be found first in the order
# specified before the default ones are searched.
#
# ----------------------------------------------------------------------------
# You may need to manually set:
#  PostgreSQL_INCLUDE_DIR  - the path to where the PostgreSQL include files are.
#  PostgreSQL_LIBRARY_DIR  - The path to where the PostgreSQL library files are.
# If FindPostgreSQL.cmake cannot find the include files or the library files.

HTH

Mike

Michael Surette
  • 701
  • 1
  • 4
  • 12
0

Add postgreSQL lib, bin, include directories to the environment variables

basjak
  • 93
  • 9
  • 1
    Please add further details to expand on your answer, such as working code or documentation citations. – Community Sep 01 '21 at 17:30
0

This could help if you installed/updated PostgreSQL with homebrew.

There were recent updates to CMake which are related to PostgreSQL and homebrew. Quoting from CMake commit: "As of 14.5, homebrew names PostgreSQL directories with the version number, e.g., postgresql@14."

Updating CMake to the latest version fixed this issue for me. Installing cmake with homebrew Note: My answer is relevant for those having the same or similar issue after PostgreSQL 14.5.

OptxPrime
  • 9
  • 1
  • 2
0

It helped me to add the following 2 lines to cmake

set(PostgreSQL_ADDITIONAL_VERSIONS "15.3")
set(PostgreSQL_ROOT "C:/Program Files/PostgreSQL/15")

And cmake found the files it needed on its own

Replace the version with the one you have installed, I installed postgresql through the official installer

Sirok_ 1
  • 1
  • 1