Requested Help - Literature

Hello.

I’ve had no luck asking Dr. Google so maybe someone here can point me to some helpful resources. I’m trying to get C to connect to my sqlite3 database. C is installed in my C: drive. The database is already set up on a partitioned part of my hard drive (E:).

Stack overflow, while always helpful, didn’t ultimately help figure out what mistake I was making. Has anyone used C to connect to a sqlite3 DB before?

Thanks.

Can you show what you’re doing? Are you using an sqlite library or are you spawning a child process? Also, show us some output, what’s the exact error/problem?

Here is my first initial code:

#include<stdio.h>
#include<sqlite3.h>
//#include <windows.h>

int main(void) {

sqlite3 *db;
sqlite3_stmt *res;

int rc = sqlite3_open(":memory:", &db);

if (rc != SQLITE_OK) {
    
    fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    
    return 1;
}

rc = sqlite3_prepare_v2(db, "SELECT SQLITE_VERSION()", -1, &res, 0);    

if (rc != SQLITE_OK) {
    
    fprintf(stderr, "Failed to fetch data: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    
    return 1;
}    

rc = sqlite3_step(res);

if (rc == SQLITE_ROW) {
    printf("%s\n", sqlite3_column_text(res, 0));
}

sqlite3_finalize(res);
sqlite3_close(db);

return 0;

}
‘’’

It’s saying it can’t find references to almost every command.

sql3lite_connect.c:(.text+0x22): undefined reference to sqlite3_open’`

It’s like that for every function.

Is that the name of your file? If so then that suggests a linker error. It can’t find the implementation of those functions anywhere in your source files and in the system libraries that are automatically included. You’ll need to find out where the sql library is on your system and include it in the compile command.