.\" Man page generated from reStructuredText. . . .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 .. .TH "BSON_INCLUDE_AND_LINK" "3" "Apr 02, 2024" "1.26.2" "libbson" .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 .EX #include #include int main (int argc, const char **argv) { bson_t *b; char *j; b = BCON_NEW (\(dqhello\(dq, BCON_UTF8 (\(dqbson!\(dq)); j = bson_as_canonical_extended_json (b, NULL); printf (\(dq%s\en\(dq, j); bson_free (j); bson_destroy (b); return 0; } .EE .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 .EX # Specify the minimum version you require. find_package (bson\-1.0 1.7 REQUIRED) # The \(dqhello_bson.c\(dq sample program is shared among four tests. add_executable (hello_bson ../../hello_bson.c) target_link_libraries (hello_bson PRIVATE mongo::bson_shared) .EE .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 .EX # Specify the minimum version you require. find_package (bson\-1.0 1.7 REQUIRED) # The \(dqhello_bson.c\(dq sample program is shared among four tests. add_executable (hello_bson ../../hello_bson.c) target_link_libraries (hello_bson PRIVATE mongo::bson_static) .EE .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 .EX gcc \-o hello_bson hello_bson.c $(pkg\-config \-\-libs \-\-cflags libbson\-1.0) .EE .UNINDENT .UNINDENT .sp Or to statically link to libbson: .INDENT 0.0 .INDENT 3.5 .sp .EX gcc \-o hello_bson hello_bson.c $(pkg\-config \-\-libs \-\-cflags libbson\-static\-1.0) .EE .UNINDENT .UNINDENT .SH AUTHOR MongoDB, Inc .SH COPYRIGHT 2017-present, MongoDB, Inc .\" Generated by docutils manpage writer. .