Error: Undefined reference to 'sqlite3_open'

1

I am creating a software in C that uses SQLite 3 as a database, but 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'm using this <sqlite3.h> library and compiling with GCC.

    
asked by anonymous 26.10.2015 / 23:18

1 answer

3

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

gcc main.c sqlite3.c -lpthread -ldl
    
26.10.2015 / 23:23