Mongodb Client-Side Field Level Encryption (CSFLE) :fatal error: mongocrypt.h not found

I’m trying to implement the MongoDB client-side field-level encryption in Go. When I try to run the project, I’m getting the below error.

sudo go build -tags cse main.go

# go.mongodb.org/mongo-driver/x/mongo/driver/mongocrypt …/…/go/pkg/mod/go.mongodb.org/mongo-driver@v1.4.0/x/mongo/driver/mongocrypt/binary.go:11:11: fatal error: mongocrypt.h: No such file or directory // #include <mongocrypt.h> ^~~~~~~~~~~~~~ compilation terminated.

I followed the steps mentioned in this tutorial. Installed libmongocrypt

MongoDB Version used:4.4 enterprise edition.
OS: Ubuntu 18.4/Windows
go version:1.15
Please help me to resolve this issue.

Hi @Viveka_BC,

To verify that libmongocrypt was successfully installed, can you run the following command and post the output in a comment:

pkg-config --cflags --libs libmongocrypt

This will help us ensure that the installation worked and will also let us see where the required files are installed. Based on this information, we can provide follow-up debugging steps.

– Divjot

Hi @Divjot_Arora ,
This is the output I got:
-DBSON_STATIC -I/usr/local/include/mongocrypt -I/usr/local/include/libbson-1.0 -L/usr/local/lib -lmongocrypt -lbson-static-1.0 /usr/lib/x86_64-linux-gnu/librt.so /usr/lib/x86_64-linux-gnu/libm.so -pthread

@Viveka_BC the output you provided is not consistent with the instructions you claim to have followed. It appears that you might have another libmongocrypt installation in /usr/local and that it may have been only partially uninstalled. Could you provide the complete output of the following command:

pkg-config --debug --cflags --libs libmongocrypt

(Note the addition of the --debug option).

Please find the details below:

Error printing enabled by default due to use of output options besides --exists, --atleast/exact/max-version or --list-all. Value of --silence-errors: 0
Error printing enabled
Adding virtual 'pkg-config' package to list of known packages
Cannot open directory #1 '/usr/local/lib/x86_64-linux-gnu/pkgconfig' in package search path: No such file or directory
Scanning directory #2 '/usr/local/lib/pkgconfig'
File 'libbson-1.0.pc' appears to be a .pc file
Will find package 'libbson-1.0' in file '/usr/local/lib/pkgconfig/libbson-1.0.pc'
File 'libbson-static-1.0.pc' appears to be a .pc file
Will find package 'libbson-static-1.0' in file '/usr/local/lib/pkgconfig/libbson-static-1.0.pc'
File 'libmongocrypt.pc' appears to be a .pc file
Will find package 'libmongocrypt' in file '/usr/local/lib/pkgconfig/libmongocrypt.pc'
Cannot open directory #3 '/usr/local/share/pkgconfig' in package search path: No such file or directory
Scanning directory #4 '/usr/lib/x86_64-linux-gnu/pkgconfig'
File 'libkms_message.pc' appears to be a .pc file
Will find package 'libkms_message' in file '/usr/lib/x86_64-linux-gnu/pkgconfig/libkms_message.pc'
File 'openssl.pc' appears to be a .pc file
Will find package 'openssl' in file '/usr/lib/x86_64-linux-gnu/pkgconfig/openssl.pc'
File 'libbson-1.0.pc' appears to be a .pc file
File 'libbson-1.0.pc' ignored, we already know about package 'libbson-1.0'
File 'snappy.pc' appears to be a .pc file
Will find package 'snappy' in file '/usr/lib/x86_64-linux-gnu/pkgconfig/snappy.pc'
File 'ruby-2.5.pc' appears to be a .pc file
Will find package 'ruby-2.5' in file '/usr/lib/x86_64-linux-gnu/pkgconfig/ruby-2.5.pc'
File 'libmongocrypt.pc' appears to be a .pc file
File 'libmongocrypt.pc' ignored, we already know about package 'libmongocrypt'
File 'libmongoc-1.0.pc' appears to be a .pc file
Will find package 'libmongoc-1.0' in file '/usr/lib/x86_64-linux-gnu/pkgconfig/libmongoc-1.0.pc'
File 'geoclue-2.0.pc' appears to be a .pc file
Will find package 'geoclue-2.0' in file '/usr/lib/x86_64-linux-gnu/pkgconfig/geoclue-2.0.pc'
File 'libmongoc-ssl-1.0.pc' appears to be a .pc file
Will find package 'libmongoc-ssl-1.0' in file '/usr/lib/x86_64-linux-gnu/pkgconfig/libmongoc-ssl-1.0.pc'
File 'zlib.pc' appears to be a .pc file
Will find package 'zlib' in file '/usr/lib/x86_64-linux-gnu/pkgconfig/zlib.pc'
File 'libcrypto.pc' appears to be a .pc file
Will find package 'libcrypto' in file '/usr/lib/x86_64-linux-gnu/pkgconfig/libcrypto.pc'
File 'xorg-wacom.pc' appears to be a .pc file
Will find package 'xorg-wacom' in file '/usr/lib/x86_64-linux-gnu/pkgconfig/xorg-wacom.pc'
File 'ruby.pc' appears to be a .pc file
Will find package 'ruby' in file '/usr/lib/x86_64-linux-gnu/pkgconfig/ruby.pc'
File 'libmongocrypt-static.pc' appears to be a .pc file
Will find package 'libmongocrypt-static' in file '/usr/lib/x86_64-linux-gnu/pkgconfig/libmongocrypt-static.pc'
File 'libsasl2.pc' appears to be a .pc file
Will find package 'libsasl2' in file '/usr/lib/x86_64-linux-gnu/pkgconfig/libsasl2.pc'
File 'libssl.pc' appears to be a .pc file
Will find package 'libssl' in file '/usr/lib/x86_64-linux-gnu/pkgconfig/libssl.pc'
Scanning directory #5 '/usr/lib/pkgconfig'
File 'ibus-table.pc' appears to be a .pc file
Will find package 'ibus-table' in file '/usr/lib/pkgconfig/ibus-table.pc'
Scanning directory #6 '/usr/share/pkgconfig'
File 'yelp-xsl.pc' appears to be a .pc file
Will find package 'yelp-xsl' in file '/usr/share/pkgconfig/yelp-xsl.pc'
File 'udev.pc' appears to be a .pc file
Will find package 'udev' in file '/usr/share/pkgconfig/udev.pc'
File 'm17n-db.pc' appears to be a .pc file
Will find package 'm17n-db' in file '/usr/share/pkgconfig/m17n-db.pc'
File 'poppler-data.pc' appears to be a .pc file
Will find package 'poppler-data' in file '/usr/share/pkgconfig/poppler-data.pc'
File 'mobile-broadband-provider-info.pc' appears to be a .pc file
Will find package 'mobile-broadband-provider-info' in file '/usr/share/pkgconfig/mobile-broadband-provider-info.pc'
File 'fontutil.pc' appears to be a .pc file
Will find package 'fontutil' in file '/usr/share/pkgconfig/fontutil.pc'
File 'iso-codes.pc' appears to be a .pc file
Will find package 'iso-codes' in file '/usr/share/pkgconfig/iso-codes.pc'
File 'adwaita-icon-theme.pc' appears to be a .pc file
Will find package 'adwaita-icon-theme' in file '/usr/share/pkgconfig/adwaita-icon-theme.pc'
File 'xkeyboard-config.pc' appears to be a .pc file
Will find package 'xkeyboard-config' in file '/usr/share/pkgconfig/xkeyboard-config.pc'
File 'systemd.pc' appears to be a .pc file
Will find package 'systemd' in file '/usr/share/pkgconfig/systemd.pc'
File 'shared-mime-info.pc' appears to be a .pc file
Will find package 'shared-mime-info' in file '/usr/share/pkgconfig/shared-mime-info.pc'
File 'usbutils.pc' appears to be a .pc file
Will find package 'usbutils' in file '/usr/share/pkgconfig/usbutils.pc'
File 'bash-completion.pc' appears to be a .pc file
Will find package 'bash-completion' in file '/usr/share/pkgconfig/bash-completion.pc'
File 'xkbcomp.pc' appears to be a .pc file
Will find package 'xkbcomp' in file '/usr/share/pkgconfig/xkbcomp.pc'
File 'xbitmaps.pc' appears to be a .pc file
Will find package 'xbitmaps' in file '/usr/share/pkgconfig/xbitmaps.pc'
Looking for package 'libmongocrypt'
Looking for package 'libmongocrypt-uninstalled'
Reading 'libmongocrypt' from file '/usr/local/lib/pkgconfig/libmongocrypt.pc'
Parsing package file '/usr/local/lib/pkgconfig/libmongocrypt.pc'
  line>Name: mongocrypt
  line>Description: The libmongocrypt client-side field level encryption library.
  line>Version: 1.1.0-pre2+20201126gitbe0a08387e
  line>Requires: libbson-static-1.0
  line>Requires.private: 
  line>prefix=/usr/local
 Variable declaration, 'prefix' has value '/usr/local'
  line>includedir=${prefix}/include/mongocrypt
 Variable declaration, 'includedir' has value '/usr/local/include/mongocrypt'
  line>libdir=${prefix}/lib
 Variable declaration, 'libdir' has value '/usr/local/lib'
  line>Libs: -L${libdir} -lmongocrypt
  line>Cflags: -I${includedir}
Path position of 'libmongocrypt' is 2
Adding 'libmongocrypt' to list of known packages
Searching for 'libmongocrypt' requirement 'libbson-static-1.0'
Looking for package 'libbson-static-1.0'
Looking for package 'libbson-static-1.0-uninstalled'
Reading 'libbson-static-1.0' from file '/usr/local/lib/pkgconfig/libbson-static-1.0.pc'
Parsing package file '/usr/local/lib/pkgconfig/libbson-static-1.0.pc'
  line>prefix=/usr/local
 Variable declaration, 'prefix' has value '/usr/local'
  line>exec_prefix=${prefix}
 Variable declaration, 'exec_prefix' has value '/usr/local'
  line>libdir=${prefix}/lib
 Variable declaration, 'libdir' has value '/usr/local/lib'
  line>includedir=${exec_prefix}/include
 Variable declaration, 'includedir' has value '/usr/local/include'
  line>
  line>Name: libbson static archive
  line>Description: The libbson BSON serialization library.
  line>Version: 1.18.0-pre
  line>Libs: -L${libdir} -lbson-static-1.0  /usr/lib/x86_64-linux-gnu/librt.so /usr/lib/x86_64-linux-gnu/libm.so -pthread
  line>Cflags: -I${includedir}/libbson-1.0 -DBSON_STATIC
Path position of 'libbson-static-1.0' is 2
Adding 'libbson-static-1.0' to list of known packages
  pre-remove: libmongocrypt libbson-static-1.0
 post-remove: libmongocrypt libbson-static-1.0
adding CFLAGS_OTHER string "-DBSON_STATIC "
  pre-remove: libmongocrypt libbson-static-1.0
 post-remove: libmongocrypt libbson-static-1.0
 original: libmongocrypt libbson-static-1.0
   sorted: libmongocrypt libbson-static-1.0
 removing duplicate "-I/usr/local/include/libbson-1.0"
adding CFLAGS_I string "-I/usr/local/include/mongocrypt -I/usr/local/include/libbson-1.0 "
  pre-remove: libmongocrypt libbson-static-1.0
 post-remove: libmongocrypt libbson-static-1.0
 original: libmongocrypt libbson-static-1.0
   sorted: libmongocrypt libbson-static-1.0
 removing duplicate "-L/usr/local/lib"
 removing duplicate "-L/usr/local/lib"
adding LIBS_L string "-L/usr/local/lib "
  pre-remove: libmongocrypt libbson-static-1.0
 post-remove: libmongocrypt libbson-static-1.0
 removing duplicate "-lbson-static-1.0"
 removing duplicate "/usr/lib/x86_64-linux-gnu/librt.so"
 removing duplicate "/usr/lib/x86_64-linux-gnu/libm.so"
 removing duplicate "-pthread"
adding LIBS_OTHER | LIBS_l string "-lmongocrypt -lbson-static-1.0 /usr/lib/x86_64-linux-gnu/librt.so /usr/lib/x86_64-linux-gnu/libm.so -pthread "
returning flags string "-DBSON_STATIC -I/usr/local/include/mongocrypt -I/usr/local/include/libbson-1.0 -L/usr/local/lib -lmongocrypt -lbson-static-1.0 /usr/lib/x86_64-linux-gnu/librt.so /usr/lib/x86_64-linux-gnu/libm.so -pthread"
-DBSON_STATIC -I/usr/local/include/mongocrypt -I/usr/local/include/libbson-1.0 -L/usr/local/lib -lmongocrypt -lbson-static-1.0 /usr/lib/x86_64-linux-gnu/librt.so /usr/lib/x86_64-linux-gnu/libm.so -pthread

@Viveka_BC, as I suspected, you have an installation of the C driver and libmongocrypt under /usr/local. The pkg-config files are being found there (at lines 7-11 of the output you provided). You should either remove the C driver and libmongocrypt installations located under /usr/local or remove the distribution packages you installed. It is best to only have one or the other present on your system in order to avoid issues like what you have encountered.

3 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.