1BSON_INCLUDE_AND_LINK(3) libbson BSON_INCLUDE_AND_LINK(3)
2
3
4
6 bson_include_and_link - Using libbson In Your C Program
7
9 All libbson's functions and types are available in one header file.
10 Simply include bson.h:
11
12 hello_bson.c
13
14 #include <stdio.h>
15 #include <bson/bson.h>
16
17 int
18 main (int argc, const char **argv)
19 {
20 bson_t *b;
21 char *j;
22
23 b = BCON_NEW ("hello", BCON_UTF8 ("bson!"));
24 j = bson_as_canonical_extended_json (b, NULL);
25 printf ("%s\n", j);
26
27 bson_free (j);
28 bson_destroy (b);
29
30 return 0;
31 }
32
33
35 The libbson installation includes a CMake config-file package, so you
36 can use CMake's find_package command to import libbson's CMake target
37 and link to libbson (as a shared library):
38
39 CMakeLists.txt
40
41 # Specify the minimum version you require.
42 find_package (bson-1.0 1.7 REQUIRED)
43
44 # The "hello_bson.c" sample program is shared among four tests.
45 add_executable (hello_bson ../../hello_bson.c)
46 target_link_libraries (hello_bson PRIVATE mongo::bson_shared)
47
48
49 You can also use libbson as a static library instead: Use the
50 mongo::bson_static CMake target:
51
52 # Specify the minimum version you require.
53 find_package (bson-1.0 1.7 REQUIRED)
54
55 # The "hello_bson.c" sample program is shared among four tests.
56 add_executable (hello_bson ../../hello_bson.c)
57 target_link_libraries (hello_bson PRIVATE mongo::bson_static)
58
59
61 If you're not using CMake, use pkg-config on the command line to set
62 header and library paths:
63
64 gcc -o hello_bson hello_bson.c $(pkg-config --libs --cflags libbson-1.0)
65
66
67 Or to statically link to libbson:
68
69 gcc -o hello_bson hello_bson.c $(pkg-config --libs --cflags libbson-static-1.0)
70
71
73 MongoDB, Inc
74
76 2017-present, MongoDB, Inc
77
78
79
80
811.17.4 Feb 04, 2021 BSON_INCLUDE_AND_LINK(3)