undefined reference to `sqlite3_open'

I would use sqlite3 db got this snippet

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <stdio.h>
#include <sqlite3.h>
#include <iostream>


int main() {
    sqlite3 *db;
    char *zErrMsg = 0;
    int rc;
    rc = sqlite3_open("test.db", &db);
    if(rc)
        std::cout << "connection opened" << std::endl;
    else
        std::cout << "connection failed" << std::endl;
    return 0;
}


And get the error : undefined reference to `sqlite3_open'

sqlite3 is installed and run
also installed sqlitestudio and run
also installed apt-get install libsqlite3-dev

 
 locate sqlite3.h


> /opt/sqlite-autoconf-3260000/sqlite3.h
> /usr/local/include/sqlite3.h

I'm using CLion ide

with c++17













Last edited on
Either you are not linking against the sqlite3 library (if you want to use a pre-existing sqlite library) or you are not compiling the appropriate sqlite3 cpp files.

Header files tell the compiler that the function exists.
Cpp files or libraries contain the actual function implementation.
The error message you see means that the linker cannot find the actual function implementation, so you're either not linking against the library, or you're not compiling the right *.cpp files.
Last edited on
thankyou for your answer
unfortunately I'm really quite new to c++ , above for compile and linking process

following the tutorial cmake clion I added the last two lines lines to make file
1
2
3
4
5
6
7
8
9
10
cmake_minimum_required(VERSION 3.13)
project(testdb)

set(CMAKE_CXX_STANDARD 17)

add_executable(testdb main.cpp)

#lines added
include_directories( /usr/local/lib )
find_package ( sqlite3  REQUIRED /usr/local/lib/libsqlite3.so)


and these are errors
/opt/clion-2018.3.1/bin/cmake/linux/bin/cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" /home/adriano/data/progetti/clion/testdb
CMake Error at CMakeLists.txt:9 (find_package):
By not providing "Findsqlite3.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "sqlite3", but
CMake did not find one.

Could not find a package configuration file provided by "sqlite3" with any
of the following names:

sqlite3Config.cmake
sqlite3-config.cmake

Add the installation prefix of "sqlite3" to CMAKE_PREFIX_PATH or set
"sqlite3_DIR" to a directory containing one of the above files. If
"sqlite3" provides a separate development package or SDK, be sure it has
been installed.

-- Configuring incomplete, errors occurred!
See also "/home/adriano/data/progetti/clion/testdb/cmake-build-debug/CMakeFiles/CMakeOutput.log".

[Finished]


I don't want to recompile sqlite
I want to just "use" the library
the directory /usr/local/lib should contains all the necessary

1
2
3
4
5
-rw-r--r--  1 root root  13452614 Dec 28 08:02 libsqlite3.a
-rwxr-xr-x  1 root root       956 Dec 28 08:02 libsqlite3.la*
lrwxrwxrwx  1 root root        19 Dec 28 08:02 libsqlite3.so -> libsqlite3.so.0.8.6*
lrwxrwxrwx  1 root root        19 Dec 28 08:02 libsqlite3.so.0 -> libsqlite3.so.0.8.6*
-rwxr-xr-x  1 root root   5496672 Dec 28 08:02 libsqlite3.so.0.8.6*

Topic archived. No new replies allowed.