I am trying to use the wal implementation of sqlite. sqlite3WalOpen and sqlite3WalClose are in the wal header file, and its definition exists but when I try to compile the program that uses the wal implementation I get:
/usr/bin/ld: /tmp/ccmbSleS.o: in function `main':
usewal.c:(.text+0x143): undefined reference to `sqlite3WalOpen'
/usr/bin/ld: usewal.c:(.text+0x183): undefined reference to `sqlite3WalClose'
collect2: error: ld returned 1 exit status
This is the code
#include <stdio.h>
#include "wal.h"
int main() {
printf("got here\n");
sqlite3 *db;
int rc;
// Open the SQLite database.
rc = sqlite3_open("mydatabase.db", &db);
if (rc != SQLITE_OK) {
fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
return rc;
}
sqlite3_file *pDbFd = NULL;
// Obtain the database file descriptor using SQLITE_FCNTL_FILE_POINTER.
rc = sqlite3_file_control(db, "main", SQLITE_FCNTL_FILE_POINTER, &pDbFd);
if (rc != SQLITE_OK) {
fprintf(stderr, "Error obtaining the database file descriptor: %s\n", sqlite3_errmsg(db));
sqlite3_close(db);
return rc;
}
const char *zWalName = "mydatabase-wal";
int bNoShm = 0; // Use the default WAL mode, not heap-memory mode
i64 mxWalSize = 0; // Don't truncate the WAL file
Wal *pWal = NULL;
rc = sqlite3WalOpen(sqlite3_vfs_find(zWalName), pDbFd, zWalName, bNoShm, mxWalSize, &pWal);
if (rc == SQLITE_OK) {
printf("WAL file opened successfully.\n");
// Perform WAL-related operations here if needed.
// Close the WAL file when done.
sqlite3 *dbToClose = 0; // Pass a NULL pointer for the database connection to close
sqlite3WalClose(pWal, dbToClose, 1, 0, 0);
} else {
fprintf(stderr, "Error opening WAL file: %s\n", sqlite3_errstr(rc));
}
Close the SQLite database.
sqlite3_close(db);
return 0;
}
program runs successfully without sqlite3WalX