.\" Man page generated from reStructuredText. . .TH "BSON_INCLUDE_AND_LINK" "3" "Jun 04, 2021" "1.17.6" "libbson" .SH NAME bson_include_and_link \- Using libbson In Your C Program . .nr rst2man-indent-level 0 . .de1 rstReportMargin \\$1 \\n[an-margin] level \\n[rst2man-indent-level] level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] - \\n[rst2man-indent0] \\n[rst2man-indent1] \\n[rst2man-indent2] .. .de1 INDENT .\" .rstReportMargin pre: . RS \\$1 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] . nr rst2man-indent-level +1 .\" .rstReportMargin post: .. .de UNINDENT . RE .\" indent \\n[an-margin] .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] .nr rst2man-indent-level -1 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] .in \\n[rst2man-indent\\n[rst2man-indent-level]]u .. .SH INCLUDE BSON.H .sp All libbson\(aqs functions and types are available in one header file. Simply include \fBbson.h\fP: .sp hello_bson.c .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C #include #include int main (int argc, const char **argv) { bson_t *b; char *j; b = BCON_NEW ("hello", BCON_UTF8 ("bson!")); j = bson_as_canonical_extended_json (b, NULL); printf ("%s\en", j); bson_free (j); bson_destroy (b); return 0; } .ft P .fi .UNINDENT .UNINDENT .SH CMAKE .sp The libbson installation includes a \fI\%CMake config\-file package\fP, so you can use CMake\(aqs \fI\%find_package\fP command to import libbson\(aqs CMake target and link to libbson (as a shared library): .sp CMakeLists.txt .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C # Specify the minimum version you require. find_package (bson\-1.0 1.7 REQUIRED) # The "hello_bson.c" sample program is shared among four tests. add_executable (hello_bson ../../hello_bson.c) target_link_libraries (hello_bson PRIVATE mongo::bson_shared) .ft P .fi .UNINDENT .UNINDENT .sp You can also use libbson as a static library instead: Use the \fBmongo::bson_static\fP CMake target: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C # Specify the minimum version you require. find_package (bson\-1.0 1.7 REQUIRED) # The "hello_bson.c" sample program is shared among four tests. add_executable (hello_bson ../../hello_bson.c) target_link_libraries (hello_bson PRIVATE mongo::bson_static) .ft P .fi .UNINDENT .UNINDENT .SH PKG-CONFIG .sp If you\(aqre not using CMake, use \fI\%pkg\-config\fP on the command line to set header and library paths: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C gcc \-o hello_bson hello_bson.c $(pkg\-config \-\-libs \-\-cflags libbson\-1.0) .ft P .fi .UNINDENT .UNINDENT .sp Or to statically link to libbson: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C gcc \-o hello_bson hello_bson.c $(pkg\-config \-\-libs \-\-cflags libbson\-static\-1.0) .ft P .fi .UNINDENT .UNINDENT .SH AUTHOR MongoDB, Inc .SH COPYRIGHT 2017-present, MongoDB, Inc .\" Generated by docutils manpage writer. .