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