Error: Undefined reference to 'sqlite3_open'

Asked

Viewed 346 times

1

I am creating a software in C that uses Sqlite 3 as database, however, when compiling the project Codeblocks returns me the following error message:

createdata. c|| undefined reference to 'sqlite3_open'|

undefined reference to 'sqlite3_errmsg'|

How to fix this error?

My code:

int CriarBanco()
{
    sqlite3 *banco;
    char *MsgErro = 0;
    int rc;
    char *sql;

    /**Abrir banco de dados**/
    rc = sqlite3_open("produto.db", &banco);

    if(rc)
    {
        fprintf(stderr, "Nao foi possivel abrir o banco de dados.", sqlite3_errmsg(banco));
        exit(0);
    }
    else
        fprintf(stdout, "Banco aberto com sucesso.");

    return 0;
}

PS: I am using this library <sqlite3.h> and I’m compiling with GCC.

  • 1

    Windows, Linux or Mac? How did you install Sqlite on them?

  • Linux Ubuntu already installed yes.

1 answer

3


You need to have Sqlite compiled together using some variation of this command line:

gcc main.c sqlite3.c -lpthread -ldl
  • I executed the command, but return the following error:gcc: error: sqlite3.c: Arquivo ou diretório não encontrado

  • 1

    Where the file is stored sqlite3.c? I’m using linux.

  • 1

    If you do not have it, you must download https://www.sqlite.org/download.html

  • 1

    Search for sqlite-amalgamation-3090100.zip in https://www.sqlite.org/download.html

  • Blz, I’ll take a look here Leonardo.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.