CentOS7 install Mongo-C-Driver

CentOS7,
cmake version 3.17.2
gcc version 7.5.0 (GCC)

I follow this page to install my mongo-c-driver.But no way can success.

link address:
http://mongoc.org/libmongoc/current/installing.html

FIRST way:

I run this command:

yum install mongo-c-driver

result is:

No package mongo-c-driver available.
Error: Nothing to do

install failed…

SECOND way:

I download rpm mongo-c-driver-1.16.2-2.fc32.src.rpm

when I run :

[henry@localhost mongo]$ rpm -ivh mongo-c-driver-1.16.2-2.fc32.src.rpm 
Updating / installing...
   1:mongo-c-driver-1.16.2-2.fc32     ################################# [100%]

BUT, I cant find any mongoc.h in any where…

find / -xdev -name “mongoc.h”

INSTALL FAILED…again…

THIRD way:

I download release source code.
https://github.com/mongodb/mongo-c-driver/releases/download/1.16.2/mongo-c-driver-1.16.2.tar.gz

mongo-c-driver-1.16.2.tar.gz

I use cmake to build:

cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF -DCMAKE_BUILD_TYPE=Release -fPIC …

-- Looking for include file unistd.h
-- Looking for include file unistd.h - found
-- Looking for include file stdarg.h
-- Looking for include file stdarg.h - found
-- Searching for compression library zstd
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.27.1") 
-- Checking for module 'libzstd'
--   No package 'libzstd' found
--   Not found
-- Found OpenSSL: /usr/local/ssl/lib/libcrypto.a (found version "1.0.2p")  
-- Looking for ASN1_STRING_get0_data in /usr/local/ssl/lib/libcrypto.a
-- Looking for ASN1_STRING_get0_data in /usr/local/ssl/lib/libcrypto.a - not found
-- Searching for sasl/sasl.h
--   Not found (specify -DCMAKE_INCLUDE_PATH=/path/to/sasl/include for SASL support)
-- Searching for libsasl2
--   Not found (specify -DCMAKE_LIBRARY_PATH=/path/to/sasl/lib for SASL support)
-- Check size of socklen_t
-- Check size of socklen_t - done
-- Looking for res_nsearch
-- Looking for res_nsearch - found
-- Looking for res_ndestroy
-- Looking for res_ndestroy - not found
-- Looking for res_nclose
-- Looking for res_nclose - found
-- Looking for sched_getcpu
-- Looking for sched_getcpu - not found
-- Detected parameters: accept (int, struct sockaddr *, socklen_t *)
-- Searching for compression library header snappy-c.h
--   Not found (specify -DCMAKE_INCLUDE_PATH=/path/to/snappy/include for Snappy compression)
Searching for libmongocrypt
-- libmongocrypt not found. Configuring without Client-Side Field Level Encryption support.
-- Performing Test MONGOC_HAVE_SS_FAMILY
-- Performing Test MONGOC_HAVE_SS_FAMILY - Success
-- Compiling against OpenSSL
-- SASL disabled
-- Configuring done
-- Generating done
-- Build files have been written to: /home/henry/packageRoot/mongo/mongo-c-driver-1.16.2/cmake-build

I the end , it print done. I think i build success.
Then I run:

make

2 Errors accour. The content is below:

/usr/bin/ld: /usr/local/ssl/lib/libcrypto.a(bn_sqrt.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/ssl/lib/libcrypto.a(bn_exp2.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/ssl/lib/libcrypto.a(bn_gf2m.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/ssl/lib/libcrypto.a(ec_print.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/ssl/lib/libcrypto.a(rsa_gen.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/ssl/lib/libcrypto.a(rsa_saos.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/ssl/lib/libcrypto.a(rsa_pss.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/ssl/lib/libcrypto.a(dsa_gen.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/ssl/lib/libcrypto.a(dh_gen.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/ssl/lib/libcrypto.a(dso_dlfcn.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/ssl/lib/libcrypto.a(a_set.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/ssl/lib/libcrypto.a(bio_ndef.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/ssl/lib/libcrypto.a(asn_mime.o): relocation R_X86_64_32 against `.text' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/ssl/lib/libcrypto.a(bio_b64.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: /usr/local/ssl/lib/libcrypto.a(bio_asn1.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
make[2]: *** [src/libmongoc/libmongoc-1.0.so.0.0.0] Error 1
make[1]: *** [src/libmongoc/CMakeFiles/mongoc_shared.dir/all] Error 2
make: *** [all] Error 2

I search a lot . They told to add -fPIC to the CMakeCache.txt.
but I realy add .Then run make, but also failed…


(I am chinese, my English is not good…)

Please Give me some advices about how to install mongo-c-driver on CentOS7…
Thanks VERY MUCH !

:wave:

Hi @Henry_He, have you followed the instructions in the Installing libmongoc with a Package Manger documentation? It looks like CentOS 7 should have the package as long as you have EPEL repo enabled.

Oh, I dont’t know what package manager you mean.

but i download mongo-c-driver-1.16.2-2.fc32.src.rpm,
and use rpm cmd to install it … but not effect.

Thank you very much…
I don’t install EPEL( the package manager).

I do these:
sudo yum -y install epel-release
sudo yum -y install mongo-c-driver

this time, It can download success.
And it print :

Installed:
mongo-c-driver.x86_64 0:1.3.6-1.el7

Dependency Installed:
libbson.x86_64 0:1.3.5-6.el7 mongo-c-driver-libs.x86_64 0:1.3.6-1.el7

Complete!

After install mongo-c-driver success.
I find that , the version is too old.
And I still can’t find mongoc.h

Another question.
Do you konw why?
When I build mongo-c-driver source project, why can’t build success…

When I run
rpm -ivh mongo-c-driver-1.16.2-2.fc32.src.rpm
why have no effect.

I try a lot , and finally I successed, Even though I don’t know how did it success.

If necessary, you should run this first:

sudo yum install perl-core perl pcre-devel zlib-devel cyrus-sasl-devel

STEP1:
I rebuild openssl project with -fPIC
like this:

./config no-shared zlib-dynamic -fPIC

and run cmd:

make test

all tests passed.

STEP2:
I checked my openssl PATH, and find that i did not add ‘/usr/local/ssl/bin’ to path
This is my config in ~/.bash_profile . you can look.

PATH=$PATH:$HOME/.local/bin:$HOME/bin:/usr/local/bin:/usr/local/ssl/bin:/usr/local/python3/bin:/usr/local/include/libmongoc-1.0:/usr/local/include/libbson-1.0
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/lib64:/usr/lib64
CC=/usr/local/bin/gcc
CXX=/usr/local/bin/g++
OPENSSL_ROOT_DIR=/usr/local/ssl
OPENSSL_CRYPTO_LIBRARY=/usr/local/ssl/lib
OPENSSL_INCLUDE_DIR=/usr/local/ssl/include

export PATH
export LD_LIBRARY_PATH
export CC
export CXX
export OPENSSL_ROOT_DIR
export OPENSSL_CRYPTO_LIBRARY
export OPENSSL_INCLUDE_DIR

STEP3:
run command :

source ~/.bash_profile

STEP4:
rebuild mongo-c-driver project.

like this:

cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF -DCMAKE_BUILD_TYPE=Release …

sudo make

sudo make install

Finally, I successed !

@Doug_Duncan Thank you very much.

1 Like

@Henry_He A few things:

  • The installation instructions page contains a link to the Fedora package overview, which indicates that EPEL7 repository (the repository which you would be using for CentOS) contains C driver version 1.3.6, which is probably not sufficient for your use case; packages in the EPEL repository are generally only updated for security issues

  • You might consider using the ELN repository (also provided by Fedora), which tries to provide the latest versions of packages; though, I am not certain how it works with CentOS 7

  • When you install from the package manager, you need to ensure that you have the -devel package (includes the compilation headers and other components required for development against the library) in addition to the -libs package (which contains only the runtime components).

  • (not specific to building the C driver) It is difficult to understand why you are building openssl from source as it is included as a core package in CentOS and based on the information you provided, you are not building it in any special way; this also seems to have contributed to your difficulty in building the C driver

  • (not specific to building the C driver), if your setup requires you to populate LD_LIBRARY_PATH with standard system libraries (which all three that you have listed are), then something else is likely wrong with your environment

  • Also, as a general best practice, running make with sudo is not a good thing; the sequence is normally make; sudo make install as the root privileges are only needed for copying into a system directory for installation

2 Likes

@Roberto_Sanchez Thank you very much!

About the LD_LIBRARY_PATH , I hope there is no wrong with my environment.

God bless me.

Thank you again.

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