.\" Man page generated from reStructuredText. . .TH "BSON_INCLUDE_AND_LINK" "3" "Feb 23, 2019" "1.14.0" "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: 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 find libbson\(aqs header and library paths and link to libbson: CMakeLists.txt.INDENT 0.0 .INDENT 3.5 .sp .nf .ft C # Specify the minimum version you require. find_package (libbson\-1.0 1.7 REQUIRED) message ("\-\- libbson found version \e"${BSON_VERSION}\e"") message ("\-\- libbson include path \e"${BSON_INCLUDE_DIRS}\e"") message ("\-\- libbson libraries \e"${BSON_LIBRARIES}\e"") # The "hello_bson.c" sample program is shared among four tests. add_executable (hello_bson ../../hello_bson.c) target_include_directories (hello_bson PRIVATE ${BSON_INCLUDE_DIRS}) target_link_libraries (hello_bson PRIVATE ${BSON_LIBRARIES}) target_compile_definitions (hello_bson PRIVATE ${BSON_DEFINITIONS}) .ft P .fi .UNINDENT .UNINDENT .sp By default, libbson is dynamically linked. You can use libbson as a static library instead: Use the included \fBlibbson\-static\-1.0\fP config\-file package and (on Unix) link to \fBpthread\fP: .INDENT 0.0 .INDENT 3.5 .sp .nf .ft C # Specify the minimum version you require. find_package (libbson\-static\-1.0 1.7 REQUIRED) message ("\-\- libbson\-static found version \e"${BSON_STATIC_VERSION}\e"") message ("\-\- libbson\-static include path \e"${BSON_STATIC_INCLUDE_DIRS}\e"") message ("\-\- libbson\-static libraries \e"${BSON_STATIC_LIBRARIES}\e"") # The "hello_bson.c" sample program is shared among four tests. add_executable (hello_bson ../../hello_bson.c) target_include_directories (hello_bson PRIVATE ${BSON_STATIC_INCLUDE_DIRS}) target_link_libraries (hello_bson PRIVATE ${BSON_STATIC_LIBRARIES}) target_compile_definitions (hello_bson PRIVATE ${BSON_STATIC_DEFINITIONS}) .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. .