macOS Monterey中链接器查找-ltermcap(libtermcap)的位置
在macOS Monterey中,链接器从哪里找到-ltermcap?
我想弄明白在macOS Monterey系统里,链接器是从哪里找到-ltermcap(也就是libtermcap)的。我确定它在系统某个位置,因为执行以下链接命令时会报错:
cc ../stepit/stepit.o ../readline/libreadline.a testit.o -o testit Undefined symbols for architecture x86_64: "_tputs", referenced from: __rl_backspace in libreadline.a(terminal.o) __rl_cr in libreadline.a(terminal.o) _rl_ding in libreadline.a(terminal.o) __rl_standout_on in libreadline.a(terminal.o) __rl_standout_off in libreadline.a(terminal.o) __rl_enable_meta_key in libreadline.a(terminal.o) __rl_disable_meta_key in libreadline.a(terminal.o) ...
而添加-ltermcap后,链接就能成功完成,程序也能正常运行。
我执行了find / -print > allfiles,再用grep libtermcap allfiles查找,没找到匹配结果。只搜索termcap并排除手册页后,找到了以下相关文件:
3,476 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/termcap.h 18 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libtermcap.tbd 3,476 /Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/include/termcap.h 18 /Library/Developer/CommandLineTools/SDKs/MacOSX12.3.sdk/usr/lib/libtermcap.tbd 3,477 /usr/local/Cellar/ncurses/6.4/include/ncursesw/termcap.h 18 /usr/local/Cellar/ncurses/6.4/include/termcap.h 14,824 /usr/local/Cellar/ncurses/6.4/share/man/man3/curs_termcap.3x 20,106 /usr/local/Cellar/ncurses/6.4/test/demo_termcap.c 7,774 /usr/local/Cellar/ncurses/6.4/test/dots_termcap.c 168,016 /usr/lib/zsh/5.8.1/zsh/termcap.so
这里面没有类似libtermcap的库文件(zsh下的文件可能相关,但没有引用指向它)。我通过brew安装了ncurses,它的Cellar目录下有termcap相关文件,但没有编译后的库文件,而且环境变量也没指向brew或Cellar。
我需要解决这个问题的原因是:我开发了一个生成Makefile的工具,需要检测平台是否存在libtermcap,以便为程序输出合适的-D编译选项,这个工具要适配macOS、Linux、Windows、HP-UX等多平台。
内容的提问来源于stack exchange,提问作者Stan Sieler
相关产品推荐
相关产品推荐

