PostgreSQL Extension: "could not load library" error while creating C-based Extension

198 views Asked by At

I am facing an issue while trying to create a C-based PostgreSQL extension. I have the extension code available in my GitHub repository, and I am trying to load it using the CREATE EXTENSION command in PostgreSQL. However, I am encountering the following error:

ERROR: could not load library "/Users/spartacus/Desktop/GSoC/CODE/pg_cext": dlopen(/Users/spartacus/Desktop/GSoC/CODE/pg_cext, 0x000A): tried: '/Users/spartacus/Desktop/GSoC/CODE/pg_cext' (not a file), '/System/Volumes/Preboot/Cryptexes/OS/Users/spartacus/Desktop/GSoC/CODE/pg_cext' (no such file), '/Users/spartacus/Desktop/GSoC/CODE/pg_cext' (not a file)

I have verified that the extension files are present at the given location, and the necessary permissions are also set. Despite this, the extension is not loading, and the error persists.

Steps Taken to Resolve the Issue:

  1. I have checked the file permissions for the extension files, and they seem to be correct.
ls -l /Users/spartacus/Desktop/GSoC/CODE/pg_cext


total 80
-rw-r--r--@ 1 spartacus  staff    139 Jul 15 12:24 Makefile
-rw-r--r--@ 1 spartacus  staff    100 Jul 15 12:27 pg_cext--1.0.0.sql
-rw-r--r--@ 1 spartacus  staff    227 Jul 15 12:27 pg_cext.c
-rw-r--r--@ 1 spartacus  staff    157 Jul 15 11:56 pg_cext.control
-rw-r--r--  1 spartacus  staff    984 Jul 17 09:14 pg_cext.o
-rwxr-xr-x  1 spartacus  staff  16951 Jul 17 09:14 pg_cext.so
  1. I have tried reloading PostgreSQL, but the error still occurs.
  2. I have confirmed that the extension files exist at the specified location, but the error message suggests otherwise.

My Environment:

  • PostgreSQL version: postgres (PostgreSQL) 15.0
  • Operating System: MacOS [M1 chip]
  • Extension Code

Can anyone help me troubleshoot and fix this issue? Thank you in advance for your assistance!

1

There are 1 answers

0
Vinay Kumar Talreja On

I also faced some errors while developing a C extension (PostgreSQL).

There are 3 main files for any extension.

1 .c file

  1. .control file

  2. .sql file

Make sure, your system is running proper versions that are compatible with each other while developing an extension.

I hope this answers our question.


Reference => Manual.