fatal error: sqlite3.h: No such file or directory
Asked Answered
G

2

41

I'm trying to build a C application through cross compiling for a Zynq board (ARM architecture). When I type make without mentioning the ARM arch, it works fine on my laptop. But as soon as I modify the Makefile, I get an error saying:

main.c:20:43: fatal error: sqlite3.h: No such file or directory
 #include "sqlite3.h" //library for sqlite3
                                           ^
compilation terminated.
make: *** [ws_temp_server] Error 1

The Makefile looks like this:

SOURCE=lib/base64_enc.c lib/websocket.c lib/sha1.c lib/sqlite/sqlite3.c main.c 
CC = arm-xilinx-linux-gnueabi-gcc
LDFLAGS=-lpthread -ldl
INCLUDES=lib/
PROGRAM=ws_temp_server

all: $(PROGRAM)

$(PROGRAM): $(SOURCE)
    $(CC) $(SOURCE) -I$(INCLUDES) -o$(PROGRAM) $(LDFLAGS)
clean:
    rm $(PROGRAM)

What am I doing wrong? Thanks for any help I can get.

Gimp answered 10/3, 2015 at 16:52 Comment(0)
C
4

You don't provide enough information to say for sure: in particular, you don't say where the sqlite3.h file actually is on your filesystem. However, based on what you do show I suspect you need to change the INCLUDES variable, to this:

INCLUDES = lib/sqlite

(or else change the #include in your code to be #include "sqlite/sqlite3.h"). This is assuming that the header file is in the same directory as the sqlite3.c source file.

Note that this is a bad/confusing implementation. You should be putting the -I flag in the INCLUDES variable:

INCLUDES = -Ilib/sqlite
    ...
$(PROGRAM): $(SOURCE)
        $(CC) $(SOURCE) $(INCLUDES) -o$(PROGRAM) $(LDFLAGS)

INCLUDES is plural which may lead someone to believe they could add multiple directories in that variable, but if you leave it the way you have it, this will cause strange compiler errors:

INCLUDES = lib/sqlite another/dir
    ...
$(PROGRAM): $(SOURCE)
        $(CC) $(SOURCE) -I$(INCLUDES) -o$(PROGRAM) $(LDFLAGS)

will add the flags -Ilib/sqlite another/dir... note how the second directory doesn't have a -I option.

Of course, by convention you should be using CPPFLAGS (for C preprocessor flags), not INCLUDES, but... :)

Combes answered 10/3, 2015 at 17:28 Comment(5)
Thanks! I just used #include "sqlite/sqlite3.h" and it works now! :)Gimp
Hi thanks for sharing. In my case, I got it fixed running apt-get install libsqlite3-dev. (debian wheezy). HTH SomeoneRieth
@julianromera , your suggestion worked for me too. I think your answer is the correct one. You should write it down as an answer.Babysit
Since the original author's problem was fixed by my suggestion, this is clearly the right answer. The author is using a local installation of sqlite as can be seen from the information in the question, so using apt-get to install the dev kit wouldn't be what they wanted. It's good that others have this problem fixed by installing the dev kit via apt-get but that is a different problem and requires a different solution.Combes
Because, as I said above, the person posting the question had already installed libsqlite-3-dev and so the answer below, while it will help some other people who have some different problem (that they hadn't installed the package), wouldn't help the actual question that was asked here.Combes
R
161

I got this issue fixed with

$ sudo apt-get install libsqlite3-dev

(debian wheezy)

Rieth answered 1/8, 2015 at 18:38 Comment(3)
Awesome! Your suggestion fixed my issue in 2 seconds! Thanks much!Ulceration
In my case (CentOS Linux 7), the command to fix this problem was slightly different: sudo yum install libsqlite3x-devel.Stephie
Thanks, this worked like a charm.Gilford
C
4

You don't provide enough information to say for sure: in particular, you don't say where the sqlite3.h file actually is on your filesystem. However, based on what you do show I suspect you need to change the INCLUDES variable, to this:

INCLUDES = lib/sqlite

(or else change the #include in your code to be #include "sqlite/sqlite3.h"). This is assuming that the header file is in the same directory as the sqlite3.c source file.

Note that this is a bad/confusing implementation. You should be putting the -I flag in the INCLUDES variable:

INCLUDES = -Ilib/sqlite
    ...
$(PROGRAM): $(SOURCE)
        $(CC) $(SOURCE) $(INCLUDES) -o$(PROGRAM) $(LDFLAGS)

INCLUDES is plural which may lead someone to believe they could add multiple directories in that variable, but if you leave it the way you have it, this will cause strange compiler errors:

INCLUDES = lib/sqlite another/dir
    ...
$(PROGRAM): $(SOURCE)
        $(CC) $(SOURCE) -I$(INCLUDES) -o$(PROGRAM) $(LDFLAGS)

will add the flags -Ilib/sqlite another/dir... note how the second directory doesn't have a -I option.

Of course, by convention you should be using CPPFLAGS (for C preprocessor flags), not INCLUDES, but... :)

Combes answered 10/3, 2015 at 17:28 Comment(5)
Thanks! I just used #include "sqlite/sqlite3.h" and it works now! :)Gimp
Hi thanks for sharing. In my case, I got it fixed running apt-get install libsqlite3-dev. (debian wheezy). HTH SomeoneRieth
@julianromera , your suggestion worked for me too. I think your answer is the correct one. You should write it down as an answer.Babysit
Since the original author's problem was fixed by my suggestion, this is clearly the right answer. The author is using a local installation of sqlite as can be seen from the information in the question, so using apt-get to install the dev kit wouldn't be what they wanted. It's good that others have this problem fixed by installing the dev kit via apt-get but that is a different problem and requires a different solution.Combes
Because, as I said above, the person posting the question had already installed libsqlite-3-dev and so the answer below, while it will help some other people who have some different problem (that they hadn't installed the package), wouldn't help the actual question that was asked here.Combes

© 2022 - 2024 — McMap. All rights reserved.