构建 postgres 扩展时出现链接器错误

问题描述 投票:0回答:1

我正在尝试针对rocksdb构建一个postgres扩展。这是我的 makefile

MODULES = pgtam
EXTENSION = pgtam
DATA = pgtam--0.0.1.sql
PG_CPPFLAGS += -I/usr/local/include
SHLIB_LINK += -L/usr/local/lib -lrocksdb -lz -lbz2 -lsnappy -lzstd

PG_CONFIG = /usr/local/pgsql/bin/pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)

我在运行 make 时遇到此错误

gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Werror=unguarded-availability-new -Wendif-labels -Wmissing-format-attribute -Wcast-function-type -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro -g -ggdb -Og -g3 -fno-omit-frame-pointer  -fvisibility=hidden -I/usr/local/include -I. -I./ -I/usr/local/pgsql/include/server -I/usr/local/pgsql/include/internal  -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk    -c -o pgtam.o pgtam.c
gcc -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Werror=unguarded-availability-new -Wendif-labels -Wmissing-format-attribute -Wcast-function-type -Wformat-security -fno-strict-aliasing -fwrapv -Wno-unused-command-line-argument -Wno-compound-token-split-by-macro -g -ggdb -Og -g3 -fno-omit-frame-pointer  -fvisibility=hidden pgtam.o -L/usr/local/pgsql/lib -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.4.sdk   -Wl,-dead_strip_dylibs   -fvisibility=hidden -bundle -bundle_loader /usr/local/pgsql/bin/postgres -o pgtam.dylib
Undefined symbols for architecture arm64:
  "_rocksdb_get", referenced from:
      _memam_relation_set_new_filelocator in pgtam.o
      _get_table in pgtam.o
      _get_table in pgtam.o
  "_rocksdb_open", referenced from:
      _mem_tableam_handler in pgtam.o
  "_rocksdb_options_create", referenced from:
      _mem_tableam_handler in pgtam.o
  "_rocksdb_options_destroy", referenced from:
      _mem_tableam_handler in pgtam.o
  "_rocksdb_options_optimize_level_style_compaction", referenced from:
      _mem_tableam_handler in pgtam.o
  "_rocksdb_options_set_create_if_missing", referenced from:
      _mem_tableam_handler in pgtam.o
  "_rocksdb_put", referenced from:
      _memam_relation_set_new_filelocator in pgtam.o
      _set_ntables in pgtam.o
  "_rocksdb_readoptions_create", referenced from:
      _memam_relation_set_new_filelocator in pgtam.o
      _get_table in pgtam.o
      _get_table in pgtam.o
  "_rocksdb_readoptions_destroy", referenced from:
      _memam_relation_set_new_filelocator in pgtam.o
      _get_table in pgtam.o
      _get_table in pgtam.o
  "_rocksdb_writeoptions_create", referenced from:
      _memam_relation_set_new_filelocator in pgtam.o
      _set_ntables in pgtam.o
  "_rocksdb_writeoptions_destroy", referenced from:
      _memam_relation_set_new_filelocator in pgtam.o
      _set_ntables in pgtam.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [pgtam.dylib] Error 1

我希望链接成功。我检查过的事情:

  1. 我确实在包含的路径中存在 dylib
    /usr/local/lib/librocksdb.dylib
  2. dylib 确实有错误消息中的符号
╰─$ nm /usr/local/lib/librocksdb.dylib | rg _rocksdb_get
00000000000493a4 T _rocksdb_get
00000000000494f8 T _rocksdb_get_cf
000000000004992c T _rocksdb_get_cf_with_ts
0000000000056854 T _rocksdb_get_column_family_metadata
00000000000568cc T _rocksdb_get_column_family_metadata_cf
0000000000049088 T _rocksdb_get_full_history_ts_low
000000000004beb0 T _rocksdb_get_latest_sequence_number
0000000000056598 T _rocksdb_get_options_from_string
000000000005b800 T _rocksdb_get_pinned
000000000005b94c T _rocksdb_get_pinned_cf
000000000004bbd0 T _rocksdb_get_updates_since
0000000000049738 T _rocksdb_get_with_ts
postgresql rocksdb
1个回答
0
投票

回答我自己的问题,这有效

MODULE_big = pgtam
EXTENSION = pgtam
DATA = pgtam--0.0.1.sql

PG_CPPFLAGS += -L/usr/local/lib
SHLIB_LINK += -L/usr/local/lib -lrocksdb

PG_CONFIG = /usr/local/pgsql/bin/pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)

参考https://www.postgresql.org/message-id/flat/[电子邮件受保护]#c710c8c908ebfc9dc9bb4efb37cb80dc

© www.soinside.com 2019 - 2024. All rights reserved.