SQLite Forum

Compilation error when using SQLITE_OMIT_WAL in 3.45.2
Login

Compilation error when using SQLITE_OMIT_WAL in 3.45.2

(1) By anonymous on 2024-04-11 18:00:24 [source]

When using -DSQLITE_OMIT_WAL, building the amalgamation from source then building the amalgamation, the compiler chokes on the sqlite3PagerJrnlFile function:

sqlite3.c: In function ‘sqlite3PagerJrnlFile’:
sqlite3.c:63808:20: error: #if with no expression
63808 | #if SQLITE_OMIT_WAL
      |                    ^
sqlite3.c:63811:16: error: ‘Pager’ has no member named ‘pWal’
63811 |   return pPager->pWal ? sqlite3WalFile(pPager->pWal) : pPager->jfd;

This seems to be because the CPP conditional uses #if SQLITE_OMIT_WAL rather than #if(n)def

(2) By Stephan Beal (stephan) on 2024-04-11 18:10:20 in reply to 1 [link] [source]

When using -DSQLITE_OMIT_WAL, building the amalgamation from source then building the amalgamation, the compiler chokes on the sqlite3PagerJrnlFile function:

Can you show us how to reproduce this, because we can't:

$ gcc -c -DSQLITE_OMIT_WAL sqlite3.c
<no output>

same with clang.

(3) By Stephan Beal (stephan) on 2024-04-11 18:15:52 in reply to 2 [link] [source]

Can you show us how to reproduce this, because we can't:

Update:

sqlite3.c: In function ‘sqlite3PagerJrnlFile’:
sqlite3.c:63808:20: error: #if with no expression
63808 | #if SQLITE_OMIT_WAL

The error message implies that you have passed an "=" sign on the end of the -DSQLITE_OMIT_WAL=. If so, remove that and it will work again.

$ gcc -c -DSQLITE_OMIT_WAL sqlite3.c
<no output>
$ gcc -c -DSQLITE_OMIT_WAL= sqlite3.c
sqlite3.c: In function ‘sqlite3PagerJrnlFile’:
sqlite3.c:63858:20: error: #if with no expression
63858 | #if SQLITE_OMIT_WAL
...

(4) By anonymous on 2024-04-11 18:49:04 in reply to 2 [link] [source]

I can reproduce it in two different ways.

(1) My usual way to configure SQLite is to have all options as #define in a C file rather than in a Makefile. Simplifying, I have a C file that looks like this:

#define SQLITE_OMIT_WAL
#include "sqlite3.c"

It is this file that gets compiled rather than sqlite3.c (gcc -c sqlite_with_config.c)

The problem goes away if I use #define SQLITE_OMIT_WAL 1

(2) Using either the command line or a Makefile, as you did, but explicitly set -DSQLITE_OMIT_WAL=0

The documentation (https://sqlite.org/compile.html#omitfeatures) explicitly states:

The macros in this section do not require values. The following compilation switches all have the same effect:

-DSQLITE_OMIT_ALTERTABLE

-DSQLITE_OMIT_ALTERTABLE=1

-DSQLITE_OMIT_ALTERTABLE=0

As (2) proves, in this case the =0 variant does not compile.

Your usage of -D on the command line only works because the compiler automatically assigns a value of 1 to non-valued defines that come from the command line.

Moreover, as I understand it, there should be no difference of behaviour between -D and #define, they should be totally interchangeable, and we should be able to ignore the fact that -DVARIABLE really means #define VARIABLE 1.

Anyway, again, the fix is straightforward: use #if(n)def (like SQLite does everywhere else) rather than #if.

(5) By Stephan Beal (stephan) on 2024-04-11 19:01:23 in reply to 4 [link] [source]

The documentation (https://sqlite.org/compile.html#omitfeatures) explicitly states:

that...

The SQLITE_OMIT_* options are unsupported.

;)

Nonetheless, the docs clearly contradict what's happening here and a fix is pending.

(6) By anonymous on 2024-04-11 19:11:29 in reply to 5 [link] [source]

Thank you. :)

(7) By Stephan Beal (stephan) on 2024-04-11 19:12:18 in reply to 1 [link] [source]

This seems to be because the CPP conditional uses #if SQLITE_OMIT_WAL rather than #if(n)def

This is now fixed in the trunk and 3.45 branches. Thank you for the report.