'how to add DuckDB library in c++ program?

I downloaded the file https://github.com/duckdb/duckdb/releases/download/v0.3.2/libduckdb-linux-amd64.zip, but I do not know how to use it in C++.

This file contains the following files:

  • duckdb.h

    duckdb.hpp

    libduckdb.so

What should I do after downloading?

The following code that I run:

#include "duckdb.hpp"

using namespace duckdb;

int main () {
DuckDB db (nullptr);
Connection con (db);

con.Query ("CREATE TABLE integers (i INTEGER)");
con.Query ("INSERT INTO integers VALUES (3)");
auto result = con.Query ("SELECT * FROM integers");
result-> Print ();
}

Gives the following error:

undefined reference to `duckdb :: DuckDB :: DuckDB (char const *, duckdb :: DBConfig *) '


Solution 1:[1]

While compiling your code, need to link ur library i.e. use .so or .a file name.

If library name foo.so, then compilation will be done as follows(.

g++ -lfoo xyz.cpp -o xyz

keep the library in same folder as cpp file, otherwise you will need specify path as well with -L

To specify a directory to search for (binary) libraries, you just use -L:

-L/data[...]/lib

To specify a directory to search for include header files you use -I:

-I/data[...]/include/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 HrishDev