How to compile SQLite3?

2

I'm trying to run a short test with SQLite3. I can not run this program so simple! I have already researched solutions on the internet and none of them solved my problem. Follow the program, cmakelists and logs :

main.c

#include <stdio.h>
#include <pthread.h>
#include "sqlite3.h"

int main(void)
{
   sqlite3 *db;
   int rc;

   rc = sqlite3_open("test.db", &db);

   if( rc ){
      fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
      return 0;
   }else{
      fprintf(stderr, "Opened database successfully\n");
   }
   sqlite3_close(db);
   return 1;
}

And the following CMakeLists.txt

find_package(Threads)

cmake_minimum_required(VERSION 3.0)

project(Testes)

add_definitions(-Wall -g -o -std-c11 -lpthread -lcppdb_sqlite3 -ldl)

add_executable(Testes main.c)

add_library(sqlite3 sqlite3.c)

target_link_libraries(Testes sqlite3)

target_link_libraries(Testes ${CMAKE_THREAD_LIBS_INIT})

target_link_libraries(Testes ${CMAKE_DL_LIBS})

CMakeError.log

Determining if files pthread.h exist failed with the following output:

Source:
/* */
#include <pthread.h>


int main(){return 0;}
    
asked by anonymous 06.10.2015 / 15:07

1 answer

3

The solution is simpler than this. A simple build solves the problem:

gcc main.c sqlite3.c -lpthread -ldl.

Main.c would be your code.

But in this case it would even be better not to use threads :

gcc -DSQLITE_THREADSAFE=0 main.c sqlite3.c -ldl

For the rest, just take any reference to threads .

    
06.10.2015 / 16:46