Reputation: 2072
I've downloaded the sqlite3 source, and am trying to make a thin c++ wrapper to use sqlite3 in some of my applications. But I get a list of undefined references in sqlite3.c
In my database.hpp, I have the c include:
extern "C" {
#include "sqlite3.h"
}
My makefile looks like this:
CC=gcc -g
CPP=g++ -g
CFLAGS=-c -Wall -ggdb
CPPSOURCES=$(wildcard *.cpp)
CSOURCES=$(wildcard *.c)
OBJECTS=$(CPPSOURCES:.cpp=.o) $(CSOURCES:.c=.o)
EXECUTABLE=testdb
all: $(CPPSOURCES) $(CSOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
\t $(CPP) $(OBJECTS) -o $@
.cpp.o:
\t $(CPP) $(CFLAGS) &< -o $@
.c.o:
\t $(CC) $(CFLAGS) &< -o $@
clean:
\t rm -rf *o $(EXECUTABLE)
So what is missing in my Makefile? Or somewhere else .. Do I need some linker options?
tx,
aktiv
Upvotes: 1
Views: 362
Reputation: 1098
On the download page there is a tarball with a makefile.
http://www.sqlite.org/sqlite-autoconf-3070500.tar.gz
To create the library:
./configure --prefix /your/own/directory
make
make install
Whit this the "makefile" puts the headers and libs in that directory.
Then you can link like Zan explains.
Upvotes: 0
Reputation: 54325
You need to link the sqlite3 library or it won't work. I don't see any -l
parameters.
Also, there's no need for you to use those .cpp.o and .c.o Makefile commands. They'll be handled by the built-in automatic rules. You just need to use the right flag variables. For C files you use CFLAGS, for C++ files you use CXXFLAGS, for the link step you provide LDFLAGS with your -l
parameter.
Upvotes: 2