Perl operation mongodb reported an error undefined symbol: heutf8 solution

Time:2022-1-2

Because it is troublesome to operate Mongo by shell, we have to try to use Perl to operate Mongo. Perl needs to operate mongodb, and the corresponding driver must be installed first. Most people use cpan to install. Personally, I think it is too troublesome to use cpanm to install Perl module.

 

Copy codeThe code is as follows:

# cpanm MongoDB
–> Working on MongoDB
Fetching http://www.cpan.org/authors/id/F/FR/FRIEDO/MongoDB-0.702.1.tar.gz … OK
Configuring MongoDB-0.702.1 … OK
Building and testing MongoDB-0.702.1 … FAIL
! Installing MongoDB failed. See /root/.cpanm/work/1376540233.15152/build.log for details. Retry with –force to force install it.

 

Cpanm reports an error. Use the – force parameter

 

Copy codeThe code is as follows:

# cpanm MongoDB –force
–> Working on MongoDB
Fetching http://www.cpan.org/authors/id/F/FR/FRIEDO/MongoDB-0.702.1.tar.gz … OK
Configuring MongoDB-0.702.1 … OK
Building and testing MongoDB-0.702.1 … FAIL
! Testing MongoDB-0.702.1 failed but installing it anyway.
Successfully installed MongoDB-0.702.1 (upgraded from 0.702.0)
1 distribution installe

 

Everything looks good. Test script

Script content:

 

Copy codeThe code is as follows:

# cat /root/testMongo.pl
#!/usr/bin/perl
use MongoDB;
my $connection = MongoDB::Connection->new( host => ‘localhost’, port => 27017);

 

function:

 

Copy codeThe code is as follows:

# perl /root/testMongo.pl
/usr/bin/perl: symbol lookup error: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/MongoDB/MongoDB.so: undefined symbol: HeUTF8

 

Google inquired mongodb. So: undefined symbol: heutf8 and found only one related article A group of people discussed the problem. The solution of one of them is as follows:

 

Copy codeThe code is as follows:

# wget http://search.cpan.org/CPAN/authors/id/F/FR/FRIEDO/MongoDB-0.701.4.tar.gz
# tar -xzvf MongoDB-0.701.4.tar.gz
# cd MongoDB-0.701.4
Add the following to Perl_ mongo. h:
/* supply HeUTF8 if it’s missing – ppport.h doesn’t supply it, unfortunately */
 #ifndef HeUTF8
 #define HeUTF8(he) ((HeKLEN(he) == HEf_SVKEY) ? \
 SvUTF8(HeKEY_sv(he)) : \
 (U32)HeKUTF8(he))
 #endif
# perl Makefile.PL
# make
# make install

 

The Perl script runs OK

In fact, it is due to incompatibility. For the RHEL5 / centos5 distribution of the system, the last version of mongodb’s Perl driver is v0 forty-five

The following are the replies from foreign netizens:

The latest version to compile, test and install properly on Rhel5/Centos5 is v0.45 by KRISTINA. (requires Any::Moose)
https://metacpan.org/release/KRISTINA/MongoDB-0.45

Recommended Today

Explanation of websocket heartbeat reconnection

Recently, websocket has been used in the development of applet. The applet provides corresponding native API, which is different from H5 API. Therefore, some mature class libraries of popular H5 are difficult to use, and the native API has some defects, so it implements a set of heartbeat reconnection mechanism by itself. First, let’s briefly […]