CMAKE's file has this code:
cmake_minimum_required(VERSION 3.6)
project(HelloSqliteC)
set(CMAKE_CXX_STANDARD 11)
set(SOURCE_FILES main.c)
add_executable(HelloSqliteC ${SOURCE_FILES})
The file main.c has this code:
#include <stdio.h>
#include <stdlib.h>
#include <sqlite3.h>
int main() {
sqlite3 *db;
int rc;
rc = sqlite3_open("database.db", &db);
if (rc) {
fprintf(stderr, "Can't open database: %s!\n", sqlite3_errmsg(db));
} else {
fprintf(stderr, "Opened database successfully!\n");
}
sqlite3_close(db);
return 0;
}
When I've trying compiling:
/home/marcus/ide/clion/clion-2016.3.1/bin/cmake/bin/cmake --build /home/marcus/projects/native/HelloSqliteC/cmake-build-debug --target HelloSqliteC -- -j 4
[ 50%] Building C object CMakeFiles/HelloSqliteC.dir/main.c.o
[100%] Linking C executable HelloSqliteC
CMakeFiles/HelloSqliteC.dir/main.c.o: In function `main':
/home/marcus/projects/native/HelloSqliteC/main.c:13: undefined reference to `sqlite3_open'
/home/marcus/projects/native/HelloSqliteC/main.c:16: undefined reference to `sqlite3_errmsg'
/home/marcus/projects/native/HelloSqliteC/main.c:21: undefined reference to `sqlite3_close'
collect2: error: ld returned 1 exit status
CMakeFiles/HelloSqliteC.dir/build.make:94: recipe for target 'HelloSqliteC' failed
make[3]: *** [HelloSqliteC] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/HelloSqliteC.dir/all' failed
make[2]: *** [CMakeFiles/HelloSqliteC.dir/all] Error 2
CMakeFiles/Makefile2:79: recipe for target 'CMakeFiles/HelloSqliteC.dir/rule' failed
make[1]: *** [CMakeFiles/HelloSqliteC.dir/rule] Error 2
Makefile:118: recipe for target 'HelloSqliteC' failed
make: *** [HelloSqliteC] Error 2
I tried solve this issue using different ways, but no success. I'm using CLion C/C++, my OS is Ubuntu 16.04 and I install sqlite3 using autoconf.
For test, I used the main.c above and compiled in command line with "-l sqlite3" using GCC and I had success, but I want use CLion.
Help me, thanks.