我正在尝试使用 SQLite3 创建一个简单的 C++ 数据库项目,但出现以下错误:
/nix/store/039g378vc3pc3dvi9dzdlrd0i4q93qwf-binutils-2.39/bin/ld: /tmp/main-ee09d1.o: in function `main':
/home/runner/DBMSProject/./main.cpp:12: undefined reference to `sqlite3_open'
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:13: main] Error 1
我查到的所有内容都说 SQLite 需要位于 make 文件中,但我不知道如何添加它,而且我找不到任何东西告诉我如何做到这一点。附件是make文件
all: main
CXX = clang++
override CXXFLAGS += -g -Wmost -Werror
SOURCE_DIRS = . sqlite3
EXCLUDE_SRC = sqlite3/shell.c
SRCS = $(shell find . -name '.ccls-cache' -type d -prune -o -type f -name '*.cpp' -print | sed -e 's/ /\\ /g')
HEADERS = $(shell find . -name '.ccls-cache' -type d -prune -o -type f -name '*.h' -print)
main: $(SRCS) $(HEADERS)
$(CXX) $(CXXFLAGS) $(SRCS) -o "$@"
main-debug: $(SRCS) $(HEADERS)
$(CXX) $(CXXFLAGS) -U_FORTIFY_SOURCE -O0 $(SRCS) -o "$@"
clean:
rm -f main main-debug
如有任何建议,我们将不胜感激!
我尝试添加 SOURCE_DIRS 行及其下面的行,但它没有修复错误
我会做这样的事情:
all: main
CXX = clang++
CXXFLAGS += -g -Wall -Wextra -Werror
SOURCE_DIRS = . sqlite3
EXCLUDE_SRC = sqlite3/shell.c
SRCS = $(foreach dir,$(SOURCE_DIRS), $(wildcard $(dir)/*.cpp))
HEADERS = $(foreach dir,$(SOURCE_DIRS), $(wildcard $(dir)/*.h))
main: $(SRCS) $(HEADERS)
$(CXX) $(CXXFLAGS) $(SRCS) -o "$@"
main-debug: $(SRCS) $(HEADERS)
$(CXX) $(CXXFLAGS) -U_FORTIFY_SOURCE -O0 $(SRCS) -o "$@"
clean:
rm -f main main-debug