]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Add libpq dir to link options
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 29 Jun 2021 03:53:30 +0000 (04:53 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Tue, 29 Jun 2021 12:47:15 +0000 (13:47 +0100)
psycopg_c/setup.py

index 446efed3ed78c974a794df56b1347c25c19f8d2d..ffe8163d10ff1ca3d8fa53ec0ea76c1853c58b64 100644 (file)
@@ -28,6 +28,16 @@ with open("psycopg_c/version.py") as f:
     version = m.group(1)
 
 
+def get_config(what: str) -> str:
+    try:
+        out = sp.run(["pg_config", f"--{what}"], stdout=sp.PIPE, check=True)
+    except Exception as e:
+        log.error("cannot build C module: %s", e)
+        raise
+    else:
+        return out.stdout.strip().decode("utf8")
+
+
 class psycopg_build_ext(build_ext):
     def finalize_options(self) -> None:
         self._setup_ext_build()
@@ -41,18 +51,12 @@ class psycopg_build_ext(build_ext):
         if os.path.exists("psycopg_c/_psycopg.pyx"):
             from Cython.Build import cythonize
 
-        # Add the include dir for the libpq.
-        try:
-            out = sp.run(
-                ["pg_config", "--includedir"], stdout=sp.PIPE, check=True
-            )
-        except Exception as e:
-            log.error("cannot build C module: %s", e)
-            raise
-
-        includedir = out.stdout.strip().decode("utf8")
+        # Add include and lib dir for the libpq.
+        includedir = get_config("includedir")
+        libdir = get_config("libdir")
         for ext in self.distribution.ext_modules:
             ext.include_dirs.append(includedir)
+            ext.library_dirs.append(libdir)
 
         if cythonize is not None:
             for ext in self.distribution.ext_modules: