2
I’m trying to run a little test with Sqlite3. I can’t run this program that simple! I’ve 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 next 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;}
Why did you put
#include <pthread.h>
in the code?– Maniero
I thought it was necessary because of the sqlite. But I withdrew and I still have mistakes. And two of them are just about her. -- Looking for include file pthread. h - not found -- Could NOT find Threads (Missing: Threads_found)
– lys
Take away everything that refers to threads of script. Sqlite can even work with them, but it’s not recommended. If you’re going to do this, make sure you’ve mastered it, it’s very easy to miss. Compile like this:
gcc -DSQLITE_THREADSAFE=0 main.c sqlite3.c -ldl
If you still want to use it try compiling just with thisgcc main.c sqlite3.c -lpthread -ldl
. Themain.c
would be your code.– Maniero
I have no words to describe how lost I was because of this! Thank you very much. This solved my problem.
– lys