我正在将 Raspberry Pi 上的工作应用程序迁移到最新的 OS Bookworm。
在 make 时,出现以下错误:
make
clang++ -lpthread -L/usr/local/lib –lreadline -lcurl -lpigpio -o build/cpssuper build/common.cpp.o build/gpio.cpp.o build/mutex.cpp.o build/namedpipe.cpp.o build/console.cpp.o build/pcs-api-task.cpp.o build/main.cpp.o build/utils.cpp.o build/datetime.cpp.o
clang: error: no such file or directory: '–lreadline'
make: *** [Makefile:40: build/cpssuper] Error 1
我之前使用的是readline7,但这无法安装,所以我必须安装readline8。
sudo apt-get install libreadline8 libreadline-dev
安装成功,如果我运行 apt-cache,我会得到以下信息:
apt-cache search readline
beef - flexible Brainfuck interpreter
bpython - fancy interface to the Python 3 interpreter
cdecl - Turn English phrases to C or C++ declarations
clisp - GNU CLISP, a Common Lisp implementation
cupt - flexible package manager -- console interface
fim - scriptable frame buffer, X.org and ascii art image viewer
golang-github-bettercap-readline-dev - Readline is a pure go implementation for a GNU-Readline like library
golang-github-chzyer-readline-dev - Readline is a pure go implementation for a GNU-Readline like library
golang-github-thomasrooney-gexpect-dev - pure golang expect library
golang-github-wader-readline-dev - Readline is a pure go(golang) implementation for GNU-Readline like library
golang-gopkg-readline.v1-dev - Pure Go implementation for GNU Readline-like library
ledit - line editor for interactive programs
lf - terminal file manager written in Go
libconfig-model-perl - module for describing and editing configuration data
libedit-dev - BSD editline and history libraries (development files)
libedit2 - BSD editline and history libraries
libeditline-dev - development files for libeditline
libeditline0 - line editing library similar to readline
libeditreadline-dev - BSD editline and history libraries (shim development files)
libenv-ps1-perl - prompt string formatter
libghc-readline-dev - Haskell bindings to GNU readline library
libghc-readline-doc - Haskell bindings to GNU readline library; documentation
libghc-readline-prof - Haskell bindings to GNU readline library; profiling libraries
libgnatcoll-readline20 - Ada binding for ReadLine input history (runtime)
libgnatcoll-readline21-dev - Ada binding for ReadLine input history (development)
libjline-java - Java library for handling console input
libjline-java-doc - Java library for handling console input - documentation
libjline2-java - console input handling in Java
libjline3-java - Console input handling library
libreadline-dev - GNU readline and history libraries, development files
libreadline-gplv2-dev - GNU readline and history libraries, development files
libreadline-java - GNU readline and BSD editline wrappers for Java
libreadline5 - GNU readline and history libraries, run-time libraries
libreadline5-dbg - GNU readline and history libraries, debugging libraries
libreadline6 - GNU readline and history libraries, run-time libraries
libreadline6-dbg - GNU readline and history libraries, debugging libraries
libreadline8 - GNU readline and history libraries, run-time libraries
libreply-perl - lightweight extensible Perl REPL
libruby3.0 - Libraries necessary to run Ruby 3.0
libruby3.1 - Libraries necessary to run Ruby 3.1
librust-rustyline-dev - Readline implementation based on Linenoise - Rust source code
libterm-readline-gnu-perl - Perl extension for the GNU ReadLine/History Library
libterm-readline-perl-perl - Perl implementation of Readline libraries
libterm-readline-ttytter-perl - Term::ReadLine driver with special features for microblogging
libterm-readline-zoid-perl - Pure Perl implementation of Readline libraries
libterm-shellui-perl - Perl module for fully-featured shell-like command line environment
libterm-ui-perl - Term::ReadLine UI made easy
libzed-ocaml - abstract engine for text edition in OCaml (runtime)
libzed-ocaml-dev - abstract engine for text edition in OCaml (development tools)
lua-readline - readline library for the Lua language
lua-readline-dev - readline development files for the Lua language
lua-torch-trepl - REPL Package for Torch Framework
microdc2 - command-line based Direct Connect client
ncftp - User-friendly and well-featured FTP client
node-getpass - get a password from terminal
node-keypress - Make any Node ReadableStream emit "keypress" events
node-read - Read user input from stdin module for Node.js
node-ws-iconv - A set of Node libraries for various filesystem-related functions
nwall - version of wall that uses GNU readline
perl6-readline - Readline binding for Perl 6
perlconsole - small program that lets you evaluate Perl code interactively
php-readline - readline module for PHP [default]
php8.2-readline - readline module for PHP
python3-mock-open - Better mock for file I/O
python3-prompt-toolkit - library for building interactive command lines (Python 3)
python3-readlike - GNU Readline-like line editing module
python3-urwid-readline - python-urwid textbox widget that supports readline shortcuts
raku-readline - Readline binding for Raku
readline-common - GNU readline and history libraries, common files
readline-doc - GNU readline and history libraries, documentation and examples
renameutils - Programs to make file renaming easier
rlfe - Front-end using readline to "cook" input lines for other programs
rlwrap - readline feature command line wrapper
sdcv - StarDict Console Version
swi-prolog - ISO/Edinburgh-style Prolog interpreter
swi-prolog-bdb - Berkeley DB interface for SWI-Prolog
swi-prolog-core - ISO/Edinburgh-style Prolog interpreter - core system
swi-prolog-core-packages - ISO/Edinburgh-style Prolog interpreter - core packages
swi-prolog-doc - documentation and examples for SWI-Prolog
swi-prolog-full - ISO/Edinburgh-style Prolog interpreter - full suit
swi-prolog-java - Bidirectional interface between SWI-Prolog and Java
swi-prolog-nox - ISO/Edinburgh-style Prolog interpreter - without X support
swi-prolog-odbc - ODBC library for SWI-Prolog
swi-prolog-test - tests and checks for SWI-Prolog
swi-prolog-x - User interface library for SWI-Prolog - with X support
tcl-tclreadline - GNU Readline Extension for Tcl/Tk
tintin++ - classic text-based MUD client
torch-trepl - REPL Wrapper Package for Torch Framework
我的 make 文件如下所示:
CC=clang
CXX=clang++
CPPFLAGS=-std=c++14 -Isrc/ -Wall -Wextra -Weffc++ -Wno-gnu-statement-expression -Wuninitialized -Wmissing-field-initializers #-Wsign-conversion
LDFLAGS = -lpthread -L/usr/local/lib –lreadline -lcurl -lpigpio
CFLAGS=
SRC_DIR ?= src
BUILD_DIR ?= build
DEP_DIR ?= .deps
TARGET ?= $(BUILD_DIR)/cpssuper
.PHONY: default all clean run
all: $(TARGET)
DEPFLAGS= -MT $@ -MMD -MP -MF $(DEP_DIR)/$*.Td
SRC_FILES := $(shell find $(SRC_DIR) -name *.cpp)
C_SRC_FILES := $(shell find $(SRC_DIR) -name *.c)
OBJ_FILES := $(patsubst $(SRC_DIR)/%.cpp, $(BUILD_DIR)/%.cpp.o, $(SRC_FILES))
C_OBJ_FILES := $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.c.o, $(C_SRC_FILES))
POST_COMPILE = @mv -f $(DEP_DIR)/$*.Td $(DEP_DIR)/$*.d && touch $@
$(BUILD_DIR)/%.c.o: $(SRC_DIR)/%.c $(DEP_DIR)/%.d
@mkdir -p $(@D)
$(CC) $(DEPFLAGS) $(CFLAGS) -c -o $@ $<
$(POST_COMPILE)
$(BUILD_DIR)/%.cpp.o: $(SRC_DIR)/%.cpp $(DEP_DIR)/%.d
@mkdir -p $(@D)
$(CXX) $(DEPFLAGS) $(CPPFLAGS) -c -o $@ $<
$(POST_COMPILE)
$(TARGET): $(C_OBJ_FILES) $(OBJ_FILES)
$(CXX) $(LDFLAGS) -o $@ $^
run: $(TARGET)
./$(TARGET)
clean:
-rm $(OBJ_FILES)
-rm $(C_OBJ_FILES)
$(DEP_DIR)/%.d:
@mkdir -p $(@D)
.PRECIOUS: $(DEP_DIR)/%.d
include $(wildcard $(patsubst $(SRC_DIR)/%.cpp, $(DEP_DIR)/%.d, $(SRC_FILES)))
include $(wildcard $(patsubst $(SRC_DIR)/%.c, $(DEP_DIR)/%.d, $(C_SRC_FILES)))
任何帮助表示赞赏。
问题已在评论中得到解答,但只需将信息放入正确的框中即可:
问题是
Makefile
包含一个 en 破折号,U+2013,而不是连字符,U+002D。 因此,整个 –lreadline
被视为输入文件的名称,(毫不奇怪)找不到该文件。 这两个字符在许多固定宽度字体中在视觉上是相同的。
检查这一点的一种方法是将该线穿过
hexdump -C
:
$ echo 'LDFLAGS = -lpthread -L/usr/local/lib –lreadline -lcurl -lpigpio' | hexdump -C
00000000 4c 44 46 4c 41 47 53 20 3d 20 2d 6c 70 74 68 72 |LDFLAGS = -lpthr|
00000010 65 61 64 20 2d 4c 2f 75 73 72 2f 6c 6f 63 61 6c |ead -L/usr/local|
00000020 2f 6c 69 62 20 e2 80 93 6c 72 65 61 64 6c 69 6e |/lib ...lreadlin|
00000030 65 20 2d 6c 63 75 72 6c 20 2d 6c 70 69 67 70 69 |e -lcurl -lpigpi|
00000040 6f 0a |o.|
00000042
上面,
e2 80 93
是U+2013的UTF-8编码。
我推测有人在网上放了一个示例,该示例通过像 MS-Word 这样的程序“有用”地替换了某些字符,然后又被复制到
Makefile
中。