在我的项目中包含 sqlite3 时遇到问题,makefile 没有按照我的意愿进行

Having trouble including sqlite3 into my project, makefile not doing what I want

我正在尝试使用 sqlite3 制作一个供个人使用的简单数据库应用程序。我想存储食谱,并按成分搜索它们。

我创建了一个 makefile 来构建项目,但链接器无法找到文件 sqlite3.c 和 sqlite3.h

这是我的 makefile

TARGET = main
CC = gcc
CFLAGS = -std=c99 -Wall -I /home/jamie/sqlite/sqlite3 -pthread
HEADERS = sqlite3.h
SOURCES =  main.c sqlite3.c

.PHONY: compile clean

#Compile all the files. The default target
compile:
        $(CC) $(CFLAGS) $(SOURCES) $(HEADERS) -o $(TARGET)


#Remove all files that are produced after compilation
clean:
        -rm -f *.o $(TARGET)

这是我的目录结构

jamie@jamie-VirtualBox:~/sqlite$ tree
.
├── chinook
│   └── chinook.db
├── recipes
│   ├── creator.txt
│   ├── main.c
│   ├── Makefile
│   └── recipeDB.db
├── sqlite3
│   ├── aclocal.m4
│   ├── compile
│   ├── config.guess
│   ├── config.log
│   ├── config.status
│   ├── config.sub
│   ├── configure
│   ├── configure.ac
│   ├── depcomp
│   ├── INSTALL
│   ├── install-sh
│   ├── libsqlite3.la
│   ├── libtool
│   ├── ltmain.sh
│   ├── Makefile
│   ├── Makefile.am
│   ├── Makefile.fallback
│   ├── Makefile.in
│   ├── Makefile.msc
│   ├── missing
│   ├── README.txt
│   ├── Replace.cs
│   ├── shell.c
│   ├── sqlite3
│   ├── sqlite3.1
│   ├── sqlite3.c
│   ├── sqlite3ext.h
│   ├── sqlite3.h
│   ├── sqlite3.lo
│   ├── sqlite3.o
│   ├── sqlite3.pc
│   ├── sqlite3.pc.in
│   ├── sqlite3.rc
│   ├── sqlite3-shell.o
│   ├── sqlite3-sqlite3.o
│   ├── tea
│   │   ├── aclocal.m4
│   │   ├── configure
│   │   ├── configure.ac
│   │   ├── doc
│   │   │   └── sqlite3.n
│   │   ├── generic
│   │   │   └── tclsqlite3.c
│   │   ├── license.terms
│   │   ├── Makefile.in
│   │   ├── pkgIndex.tcl.in
│   │   ├── README
│   │   ├── tclconfig
│   │   │   ├── install-sh
│   │   │   └── tcl.m4
│   │   └── win
│   │       ├── makefile.vc
│   │       ├── nmakehlp.c
│   │       └── rules.vc
│   └── test.c
└── sqlite-tools-linux-x86-3260000
    ├── sqldiff
    ├── sqlite3
    └── sqlite3_analyzer

9 directories, 58 files

从存储项目的 recipes 目录中调用 "make" 会产生以下错误。我对为什么会收到这些错误感到困惑,因为我使用 -I

将 sqlite3 目录添加到我的包含路径
jamie@jamie-VirtualBox:~/sqlite/recipes$ make
gcc -std=c99 -Wall -I /home/jamie/sqlite/sqlite3 -pthread main.c sqlite3.c sqlite3.h -o main
gcc: error: sqlite3.c: No such file or directory
gcc: error: sqlite3.h: No such file or directory
Makefile:11: recipe for target 'compile' failed
make: *** [compile] Error 1
jamie@jamie-VirtualBox:~/sqlite/recipes$ 

在 main.c 中,我有以下内容:

#include "sqlite3.h"

-I 仅影响 #include 指令的搜索路径。它不影响在命令行上指定的源文件的定位方式。在makefile层面,还需要使用头文件的完整路径(如果以后在依赖中使用的话):

HEADERS = sqlite3/sqlite3.h
SOURCES =  main.c sqlite3/sqlite3.c

您也不应尝试编译头文件,因此从编译器调用中删除 $(HEADERS) 变量:

compile:
        $(CC) $(CFLAGS) $(SOURCES) -o $(TARGET)