【发布时间】:2016-11-18 20:44:23
【问题描述】:
我正在处理现有的 C 代码,现在我使用 C 中的 sqlite 创建了一个数据库。该程序运行良好。但现在我需要为此创建一个makefile。我使用
编译了程序gcc cliDemo.c -l sqlite3
但是现在因为我使用的是makefile,所以我需要把它放在makefile 中。我尝试了几件事,但没有任何效果。
EXEC = telescope
CC = gcc
CFLAGS = -Wall -fno-strict-aliasing -g -I/usr/include/libxml2 -DHAVE_CONFIG_H
LDFLAGS = -lxml2 -lpthread -lm -lz
AR = @AR@
ARFLAGS = @ARFLAGS@
RANLIB = @RANLIB@
INSTALL_MODE= -m 0755
# Include some boilerplate Gnu makefile definitions.
prefix = /usr/local
exec_prefix = ${prefix}
bindir = ${exec_prefix}/bin
libdir = ${exec_prefix}/lib
infodir = ${prefix}/share/info
includedir = ${prefix}/include
datadir = ${prefix}/share
docdir = $(datadir)/doc/telescope
localedir = $(datadir)/locale
mandir = ${prefix}/share/man
manpfx = man
man1ext = .1
man1dir = $(mandir)/$(manpfx)1man3ext = .3man3dir = $(mandir)/$(manpfx)3
htmldir = ${docdir}
SRCDIR = ./src
BINDIR = ./bin
OBJECTDIR = ./Obj
MAINOBJS = $(OBJECTDIR)/telescope.o
MAINEXEC = $(BINDIR)/telescope
OBJECTS1 = $(MAINOBJS)
all: $(EXEC)
$(EXEC): $(OBJECTS1)
$(CC) $(CFLAGS) $(OBJECTS1) $(LDFLAGS) -o $(MAINEXEC)
$(OBJECTDIR)/telescope.o: $(SRCDIR)/telescope.c
$(CC) $(CFLAGS) -c $(SRCDIR)/telescope.c -o $(OBJECTDIR)/telescope.o
clean:
rm -f $(EXEC) $(MAINEXEC) $(OBJECTS1)
# build tests
build-tests: .build-tests-post
.build-tests-pre:
# Add your pre 'build-tests' code here...
.build-tests-post: .build-tests-impl
# Add your post 'build-tests' code here...
# run tests
test: .test-post
.test-pre:
# Add your pre 'test' code here...
.test-post: .test-impl
# Add your post 'test' code here...
这是 makefile 中的代码。我不明白如何在这里链接 sqlite3。
【问题讨论】:
-
在
LDFLAGS后面加-lsqlite3不行吗? -
“我尝试了几件事,但没有任何效果。”。你到底尝试了什么?如果您不告诉我们,我们怎么能告诉您您可能做错了什么?