Intel芯片Mac编译synctex_parser.c遇x86_64未定义符号问题求助
Mac下编译synctex_parser.c失败的原因与解决方法
问题场景
在Intel芯片的Mac设备上编译synctex_parser.c文件时,执行编译命令:
gcc -fPIC -shared synctex_parser.c -o synctex_parser.so
出现链接错误:
Undefined symbols for architecture x86_64: "__synctex_base_name", referenced from: __synctex_scanner_get_tag in synctex_parser-acaaec.o "__synctex_copy_with_quoting_last_path_component", referenced from: ___synctex_open_v2 in synctex_parser-acaaec.o
相同代码与编译命令在Linux环境可正常执行,当前Mac上的clang版本信息:
$ gcc --version Apple clang version 14.0.3 (clang-1403.0.22.14.1) Target: x86_64-apple-darwin22.5.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin
失败原因
报错中未定义的__synctex_base_name和__synctex_copy_with_quoting_last_path_component是synctex的辅助工具函数。Linux环境下gcc会自动关联系统中已有的synctex依赖组件,但Mac的clang默认不会自动识别这些依赖,且synctex在Mac上的默认组件结构与Linux存在差异,导致编译时无法找到这些函数的实现代码。
修复方法
方法一:编译完整源码文件
synctex源码仓库中,缺失的函数定义在synctex_parser_utils.c文件内,编译时需将该文件一同加入命令:
gcc -fPIC -shared synctex_parser.c synctex_parser_utils.c -o synctex_parser.so
方法二:链接系统已安装的synctex库
若已通过Homebrew等工具在Mac上安装了synctex,可直接链接对应库文件:
- 确认synctex库路径:Intel芯片Mac上,Homebrew安装的库通常位于
/usr/local/lib - 修改编译命令,添加链接参数:
gcc -fPIC -shared synctex_parser.c -lsynctex -o synctex_parser.so
如果库不在默认搜索路径,需用-L指定路径:
gcc -fPIC -shared synctex_parser.c -L/usr/local/lib -lsynctex -o synctex_parser.so
内容的提问来源于stack exchange,提问作者Dolphin
相关产品推荐
相关产品推荐

