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 find libbson's header and
35 library paths and link to libbson: CMakeLists.txt.INDENT 0.0
36
37 # Specify the minimum version you require.
38 find_package (libbson-1.0 1.7 REQUIRED)
39
40 message ("-- libbson found version \"${BSON_VERSION}\"")
41 message ("-- libbson include path \"${BSON_INCLUDE_DIRS}\"")
42 message ("-- libbson libraries \"${BSON_LIBRARIES}\"")
43
44 # The "hello_bson.c" sample program is shared among four tests.
45 add_executable (hello_bson ../../hello_bson.c)
46 target_include_directories (hello_bson PRIVATE ${BSON_INCLUDE_DIRS})
47 target_link_libraries (hello_bson PRIVATE ${BSON_LIBRARIES})
48 target_compile_definitions (hello_bson PRIVATE ${BSON_DEFINITIONS})
49
50
51By default, libbson is dynamically linked. You can use libbson as a static
52library instead: Use the included libbson-static-1.0 config-file package and
53(on Unix) link to pthread:
54
55 # Specify the minimum version you require.
56 find_package (libbson-static-1.0 1.7 REQUIRED)
57
58 message ("-- libbson-static found version \"${BSON_STATIC_VERSION}\"")
59 message ("-- libbson-static include path \"${BSON_STATIC_INCLUDE_DIRS}\"")
60 message ("-- libbson-static libraries \"${BSON_STATIC_LIBRARIES}\"")
61
62 # The "hello_bson.c" sample program is shared among four tests.
63 add_executable (hello_bson ../../hello_bson.c)
64 target_include_directories (hello_bson PRIVATE ${BSON_STATIC_INCLUDE_DIRS})
65 target_link_libraries (hello_bson PRIVATE ${BSON_STATIC_LIBRARIES})
66 target_compile_definitions (hello_bson PRIVATE ${BSON_STATIC_DEFINITIONS})
67
68
70 If you're not using CMake, use pkg-config on the command line to set
71 header and library paths:
72
73 gcc -o hello_bson hello_bson.c $(pkg-config --libs --cflags libbson-1.0)
74
75
76 Or to statically link to libbson:
77
78 gcc -o hello_bson hello_bson.c $(pkg-config --libs --cflags libbson-static-1.0)
79
80
82 MongoDB, Inc
83
85 2017-present, MongoDB, Inc
86
87
88
89
901.14.0 Feb 22, 2019 BSON_INCLUDE_AND_LINK(3)