macOS: pcre2, iconv

环境

macOS 26.6.2 (25G83)

@(#)PROGRAM:ld PROJECT:ld-1267
BUILD 16:38:58 Jun  8 2026
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em armv8m.main armv8.1m.main
will use ld-classic for: armv6 armv7 armv7s i386 armv6m armv7k armv7m armv7em
LTO support using: LLVM version 21.0.0 (static support for 30, runtime is 30)
TAPI support using: Apple TAPI version 21.0.0 (tapi-2100.0.2.6)
Library search paths:
        /usr/local/lib
        /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib
        /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/swift
Framework search paths:
        /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks

pcre2

系统自带了 pcre,由 /usr/lib/pkgconfig/libpcre2-8.pc/usr/lib/pkgconfig/libpcre2-posix.pc 可知,有pcre(8.44), pcre2-8 (10.42).

由于 macOS dyld shared cache 的存在,在 /usr/lib/ 下可能看不到 libpcre2-8.0.dylib。

可以通过 python3 -c "from ctypes.util import find_library; print(find_library('pcre2-8'))" 快速验证,或者查看 httpd otool -L /usr/sbin/httpd.

pkgconfig
 % ls -al /usr/lib/pkgconfig/libpcre*
-rw-r--r--  1 root  wheel  313 Aug 13 10:51 /usr/lib/pkgconfig/libpcre.pc
-rw-r--r--  1 root  wheel  331 Aug 13 10:51 /usr/lib/pkgconfig/libpcre2-8.pc
-rw-r--r--  1 root  wheel  300 Aug 13 10:51 /usr/lib/pkgconfig/libpcre2-posix.pc 
-rw-r--r--  1 root  wheel  301 Aug 13 10:51 /usr/lib/pkgconfig/libpcreposix.pc

% % cat /usr/lib/pkgconfig/libpcre2-8.pc
# Package Information for pkg-config

prefix=/usr/local
exec_prefix=${prefix}
libdir=/usr/lib
includedir=${prefix}/include

Name: libpcre2-8
Description: PCRE2 - Perl compatible regular expressions C library (2nd API) with 8 bit character support
Version: 10.42
Libs: -L${libdir} -lpcre2-8
Libs.private:
Cflags: -I${includedir}

更多信息:(apple-oss-distributions) macOS 26.5,, (apple-oss-distributions) pcre-21/Makefile

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libpcre2-8.tbd
 % cat /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libpcre2-8.tbd
--- !tapi-tbd
tbd-version:     4
targets:         [ x86_64-macos, arm64-macos, arm64e-macos ]
install-name:    '/usr/lib/libpcre2-8.0.dylib'
current-version: 12.2
compatibility-version: 12
exports:
  - targets:         [ x86_64-macos, arm64-macos, arm64e-macos ]
    symbols:         [ _pcre2_callout_enumerate_8, _pcre2_code_copy_8, _pcre2_code_copy_with_tables_8,
                       _pcre2_code_free_8, _pcre2_compile_8, _pcre2_compile_context_copy_8,
                       _pcre2_compile_context_create_8, _pcre2_compile_context_free_8,
                       _pcre2_config_8, _pcre2_convert_context_copy_8, _pcre2_convert_context_create_8,
                       _pcre2_convert_context_free_8, _pcre2_converted_pattern_free_8,
                       _pcre2_dfa_match_8, _pcre2_general_context_copy_8, _pcre2_general_context_create_8,
                       _pcre2_general_context_free_8, _pcre2_get_error_message_8,
                       _pcre2_get_mark_8, _pcre2_get_match_data_size_8, _pcre2_get_ovector_count_8,
                       _pcre2_get_ovector_pointer_8, _pcre2_get_startchar_8, _pcre2_jit_compile_8,
                       _pcre2_jit_free_unused_memory_8, _pcre2_jit_match_8, _pcre2_jit_stack_assign_8,
                       _pcre2_jit_stack_create_8, _pcre2_jit_stack_free_8, _pcre2_maketables_8,
                       _pcre2_maketables_free_8, _pcre2_match_8, _pcre2_match_context_copy_8,
                       _pcre2_match_context_create_8, _pcre2_match_context_free_8,
                       _pcre2_match_data_create_8, _pcre2_match_data_create_from_pattern_8,
                       _pcre2_match_data_free_8, _pcre2_pattern_convert_8, _pcre2_pattern_info_8,
                       _pcre2_serialize_decode_8, _pcre2_serialize_encode_8, _pcre2_serialize_free_8,
                       _pcre2_serialize_get_number_of_codes_8, _pcre2_set_bsr_8,
                       _pcre2_set_callout_8, _pcre2_set_character_tables_8, _pcre2_set_compile_extra_options_8,
                       _pcre2_set_compile_recursion_guard_8, _pcre2_set_depth_limit_8,
                       _pcre2_set_glob_escape_8, _pcre2_set_glob_separator_8, _pcre2_set_heap_limit_8,
                       _pcre2_set_match_limit_8, _pcre2_set_max_pattern_length_8,
                       _pcre2_set_newline_8, _pcre2_set_offset_limit_8, _pcre2_set_parens_nest_limit_8,
                       _pcre2_set_recursion_limit_8, _pcre2_set_recursion_memory_management_8,
                       _pcre2_set_substitute_callout_8, _pcre2_substitute_8, _pcre2_substring_copy_byname_8,
                       _pcre2_substring_copy_bynumber_8, _pcre2_substring_free_8,
                       _pcre2_substring_get_byname_8, _pcre2_substring_get_bynumber_8,
                       _pcre2_substring_length_byname_8, _pcre2_substring_length_bynumber_8,
                       _pcre2_substring_list_free_8, _pcre2_substring_list_get_8,
                       _pcre2_substring_nametable_scan_8, _pcre2_substring_number_from_name_8 ]

补充 HEADERS 文件

fatal error: 'pcre2.h' file not found
 ../glib/gregex.c:30:10: fatal error: 'pcre2.h' file not found
   30 | #include <pcre2.h>
      |          ^~~~~~~~~
1 error generated.

既然 pkgconfig 文件提到了 includedir 为 /usr/local/include, 那只好手动执行 make 命令。

make install-nodist_includeHEADERS
 % make install-nodist_includeHEADERS --dry-run
:
list='src/pcre2.h'; test -n "/usr/local/include" || list=; \
        if test -n "$list"; then \
          echo " ./install-sh -c -d '/usr/local/include'"; \
          ./install-sh -c -d "/usr/local/include" || exit 1; \
        fi; \
        for p in $list; do \
          if test -f "$p"; then d=; else d="./"; fi; \
          echo "$d$p"; \
        done | sed '$!N;$!N;$!N;$!N;$!N;$!N;$!N;s/\n/ /g' | sed '$!N;$!N;$!N;$!N;s/\n/ /g' | \
        while read files; do \
          echo " /usr/bin/install -c -m 644 $files '/usr/local/include'"; \
          /usr/bin/install -c -m 644 $files "/usr/local/include" || exit $?; \
        done
make install-includeHEADERS
 % make install-includeHEADERS --dry-run
:
list='src/pcre2posix.h'; test -n "/usr/local/include" || list=; \
        if test -n "$list"; then \
          echo " ./install-sh -c -d '/usr/local/include'"; \
          ./install-sh -c -d "/usr/local/include" || exit 1; \
        fi; \
        for p in $list; do \
          if test -f "$p"; then d=; else d="./"; fi; \
          echo "$d$p"; \
        done | sed '$!N;$!N;$!N;$!N;$!N;$!N;$!N;s/\n/ /g' | sed '$!N;$!N;$!N;$!N;s/\n/ /g' | \
        while read files; do \
          echo " /usr/bin/install -c -m 644 $files '/usr/local/include'"; \
          /usr/bin/install -c -m 644 $files "/usr/local/include" || exit $?; \
        done

 iconv

error: undefined symbols for architecture arm64
 Undefined symbols for architecture arm64:
  "_libiconv", referenced from:
      _g_iconv in gconvert.c.o
      _g_convert_with_iconv in gconvert.c.o
      _g_convert_with_fallback in gconvert.c.o
  "_libiconv_close", referenced from:
      _g_iconv_close in gconvert.c.o
      _g_convert in gconvert.c.o
      _g_convert_with_fallback in gconvert.c.o
      _g_convert_with_fallback in gconvert.c.o
      _g_convert_with_fallback in gconvert.c.o
      _g_convert_with_fallback in gconvert.c.o
      _g_filename_display_name in gconvert.c.o
      ...
  "_libiconv_open", referenced from:
      _g_iconv_open in gconvert.c.o
      _g_iconv_open in gconvert.c.o
      _g_iconv_open in gconvert.c.o
      _g_iconv_open in gconvert.c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

workaround

env CPPFLAGS="-I/usr/local/include" LDFLAGS="-L/usr/local/lib" meson setup build
export ACLOCAL_PATH=/usr/local/share/gettext/m4

更多信息:

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libiconv.tbd
% cat /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libiconv.tbd
--- !tapi-tbd
tbd-version:     4
targets:         [ x86_64-macos, x86_64-maccatalyst, arm64e-macos, arm64e-maccatalyst ]
install-name:    '/usr/lib/libiconv.2.dylib'
current-version: 7
compatibility-version: 7
reexported-libraries:
  - targets:         [ x86_64-macos, x86_64-maccatalyst, arm64e-macos, arm64e-maccatalyst ]
    libraries:       [ '/usr/lib/libcharset.1.dylib' ]
exports:
  - targets:         [ x86_64-macos, x86_64-maccatalyst, arm64e-macos, arm64e-maccatalyst ]
    symbols:         [ ___bsd___iconv, ___bsd___iconv_free_list, ___bsd___iconv_get_list,
                       ___bsd_iconv, ___bsd_iconv_canonicalize, ___bsd_iconv_close,
                       ___bsd_iconv_open, ___bsd_iconv_open_into, ___bsd_iconv_set_relocation_prefix,
                       ___bsd_iconvctl, ___bsd_iconvlist, ___iconv, ___iconv_free_list,
                       ___iconv_get_list, __citrus_NONE_stdenc_ops, __citrus_NONE_stdenc_traits,
                       __citrus_bcs_convert_to_lower, __citrus_bcs_convert_to_upper,
                       __citrus_bcs_skip_nonws, __citrus_bcs_skip_nonws_len, __citrus_bcs_skip_ws,
                       __citrus_bcs_skip_ws_len, __citrus_bcs_strcasecmp, __citrus_bcs_strncasecmp,
                       __citrus_bcs_strtol, __citrus_bcs_strtoul, __citrus_bcs_trunc_rws_len,
                       __citrus_csmapper_open, __citrus_db_close, __citrus_db_factory_add,
                       __citrus_db_factory_add16_by_string, __citrus_db_factory_add32_by_string,
                       __citrus_db_factory_add8_by_string, __citrus_db_factory_add_by_string,
                       __citrus_db_factory_add_string_by_string, __citrus_db_factory_calc_size,
                       __citrus_db_factory_create, __citrus_db_factory_free, __citrus_db_factory_serialize,
                       __citrus_db_get_entry, __citrus_db_get_number_of_entries,
                       __citrus_db_hash_std, __citrus_db_lookup, __citrus_db_lookup16_by_string,
                       __citrus_db_lookup32_by_string, __citrus_db_lookup8_by_string,
                       __citrus_db_lookup_by_string, __citrus_db_lookup_string_by_string,
                       __citrus_db_open, __citrus_esdb_alias, __citrus_esdb_close,
                       __citrus_esdb_free_list, __citrus_esdb_get_list, __citrus_esdb_open,
                       __citrus_find_getops, __citrus_iconv_canonicalize, __citrus_iconv_close,
                       __citrus_iconv_open, __citrus_load_module, __citrus_lookup_factory_convert,
                       __citrus_lookup_get_number_of_entries, __citrus_lookup_seq_close,
                       __citrus_lookup_seq_lookup, __citrus_lookup_seq_next, __citrus_lookup_seq_open,
                       __citrus_lookup_seq_rewind, __citrus_lookup_simple, __citrus_map_file,
                       __citrus_mapper_close, __citrus_mapper_create_area, __citrus_mapper_get_mapdir_from_key,
                       __citrus_mapper_open, __citrus_mapper_open_direct, __citrus_mapper_set_persistent,
                       __citrus_memory_stream_chr, __citrus_memory_stream_getln,
                       __citrus_memory_stream_matchline, __citrus_memory_stream_skip_ws,
                       __citrus_pivot_factory_convert, __citrus_prop_parse_variable,
                       __citrus_stdenc_close, __citrus_stdenc_default, __citrus_stdenc_open,
                       __citrus_unload_module, __citrus_unmap_file, __libiconv_version,
                       __string_hash_func, _iconv, _iconv_canonicalize, _iconv_close,
                       _iconv_open, _iconv_open_into, _iconvctl, _iconvlist, _libiconv_set_relocation_prefix ]
...
posted @ 2026-09-05 22:45  UPeRVv  阅读(3)  评论(0)    收藏  举报