diff --git a/Changelog.md b/Changelog.md
--- a/Changelog.md
+++ b/Changelog.md
@@ -1,3 +1,8 @@
+### 1.6.2
+
+- Use *CApiFFI* to avoid interactive linking against C functions with HLS /
+  Haddock / GHCi repl.
+
 ### 1.6.1
 
 - Use custom *Setup.hs* to configure Haddock options on build of documentation.
diff --git a/NgxExport/Log/CLog.hs b/NgxExport/Log/CLog.hs
--- a/NgxExport/Log/CLog.hs
+++ b/NgxExport/Log/CLog.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE CPP, ForeignFunctionInterface #-}
+{-# LANGUAGE CApiFFI #-}
 
 module NgxExport.Log.CLog where
 
@@ -8,33 +8,8 @@
 
 type CLogType = Ptr () -> CUIntPtr -> CString -> CSize -> IO ()
 
--- Some tools such as hls, haddock, and ghci run interactive linking against C
--- functions plugin_ngx_http_haskell_log() and plugin_ngx_http_haskell_log_r()
--- when loading Log.hs. In Log.hs, TH declarations from Log/Gen.hs which make
--- calls to those C functions, get instantiated. Obviously, linking fails as
--- soon as we don't have a library to expose the functions because such a
--- library is built by Nginx and we don't want to use Nginx at this step.
---
--- In this workaround, the C functions get replaced by stubs when running by
--- hls or haddock. This prevents interactive linking in Log.hs. It's easy to
--- detect that the code is being run by hls or haddock: the tools define their
--- own C macro declarations __GHCIDE__ and __HADDOCK_VERSION__ respectively. To
--- prevent interactive linking in ghci, pass one of the two macro declarations
--- (or macro NGX_CSTUB, see below) in an appropriate option, e.g.
---
--- cabal repl --ghc-options=-DNGX_CSTUB --repl-options=-fobject-code
---
--- In newer haddock releases (as of 2025), option __HADDOCK_VERSION__ gets no
--- longer set. In this case, build haddocks with
---
--- cabal haddock --haddock-for-hackage --haddock-options=--optghc=-DNGX_CSTUB
-
-#if defined(__GHCIDE__) || defined(__HADDOCK_VERSION__) || defined(NGX_CSTUB)
-#define C_LOG_STUB(f) f :: CLogType; f _ _ _ _ = return ()
-C_LOG_STUB(c_log)
-C_LOG_STUB(c_log_r)
-#else
-foreign import ccall unsafe "plugin_ngx_http_haskell_log" c_log :: CLogType
-foreign import ccall unsafe "plugin_ngx_http_haskell_log_r" c_log_r :: CLogType
-#endif
+foreign import capi
+    "ngx_log_plugin_capi.h plugin_ngx_http_haskell_log" c_log :: CLogType
+foreign import capi
+    "ngx_log_plugin_capi.h plugin_ngx_http_haskell_log_r" c_log_r :: CLogType
 
diff --git a/Setup.hs b/Setup.hs
deleted file mode 100644
--- a/Setup.hs
+++ /dev/null
@@ -1,24 +0,0 @@
-import Distribution.Simple
-import Distribution.Simple.Setup
-
-import Data.List
-
-userHooks :: UserHooks
-userHooks =
-    simpleUserHooks { haddockHook = \desc lbi hooks flags -> do
-                        let (oghc, ocstub) = ("ghc", "-DNGX_CSTUB")
-                            hadflag = haddockProgramArgs flags
-                            (h, t) = break ((oghc ==) . fst) hadflag
-                            hadflag' =
-                                case uncons t of
-                                    Nothing ->
-                                        (oghc, [ocstub]) : hadflag
-                                    Just ((_, args), t') ->
-                                        h ++ (oghc, ocstub : args) : t'
-                            flags' = flags { haddockProgramArgs = hadflag' }
-                        haddockHook simpleUserHooks desc lbi hooks flags'
-                    }
-
-main :: IO ()
-main = defaultMainWithHooks userHooks
-
diff --git a/capi/ngx_log_plugin_capi.h b/capi/ngx_log_plugin_capi.h
new file mode 100644
--- /dev/null
+++ b/capi/ngx_log_plugin_capi.h
@@ -0,0 +1,8 @@
+#include <stddef.h>
+#include <stdint.h>
+
+void plugin_ngx_http_haskell_log(void *cycle, uintptr_t level,
+    char *msg, size_t len);
+void plugin_ngx_http_haskell_log_r(void *r, uintptr_t level,
+    char *msg, size_t len);
+
diff --git a/ngx-export-log.cabal b/ngx-export-log.cabal
--- a/ngx-export-log.cabal
+++ b/ngx-export-log.cabal
@@ -1,5 +1,5 @@
 name:                  ngx-export-log
-version:               1.6.1
+version:               1.6.2
 synopsis:    Native Nginx logging from configuration files and Haskell handlers
 description: Native Nginx logging from configuration files and Haskell handlers.
         .
@@ -14,12 +14,8 @@
 stability:             stable
 copyright:             2022-2026 Alexey Radkov
 category:              Network
-build-type:            Custom
-cabal-version:         2.0
-
-custom-setup
-  setup-depends:       base >= 4.8 && < 5
-                     , Cabal >= 3.0.0.0 && < 4
+build-type:            Simple
+cabal-version:         1.20
 
 source-repository head
   type:                git
@@ -37,6 +33,9 @@
   other-modules:       NgxExport.Log.Base
                      , NgxExport.Log.CLog
                      , NgxExport.Log.Gen
+
+  include-dirs:        capi
+  install-includes:    ngx_log_plugin_capi.h
 
   ghc-options:        -Wall
 
