Cmake undefined reference to pcre_free

Describe the bug

cmake error:

CMakeFiles/Core.dir/base/src/TPRegexp.cxx.o: in function `TPRegexp::operator=(TPRegexp const&)': TPRegexp.cxx:(.text+0x33): undefined reference to `pcre_free'

Expected behavior

Build installs successfully without needing to use -Dbuiltin_pcre=ON

OR

cmake issues any kind of warning or error about the pcre version

To Reproduce

Follow installation instructions on ubuntu 20.04.2 and with:
– Looking for PCRE
– Found PCRE2: /usr/include (found version “10.34”)

cmake --build . – install -j4

[ 77%] Linking CXX shared library ../lib/libCore.so
/usr/bin/ld: CMakeFiles/Core.dir/base/src/TPRegexp.cxx.o: in function `TPRegexp::operator=(TPRegexp const&)':
TPRegexp.cxx:(.text+0x33): undefined reference to `pcre_free'
/usr/bin/ld: TPRegexp.cxx:(.text+0x51): undefined reference to `pcre_free'
/usr/bin/ld: CMakeFiles/Core.dir/base/src/TPRegexp.cxx.o: in function `TPRegexp::Optimize()':
TPRegexp.cxx:(.text+0x1cd): undefined reference to `pcre_free'
/usr/bin/ld: TPRegexp.cxx:(.text+0x206): undefined reference to `pcre_study'
/usr/bin/ld: CMakeFiles/Core.dir/base/src/TPRegexp.cxx.o: in function `TPRegexp::MatchInternal(TString const&, int, int, TArrayI*) const':
TPRegexp.cxx:(.text+0x2eb): undefined reference to `pcre_exec'
/usr/bin/ld: CMakeFiles/Core.dir/base/src/TPRegexp.cxx.o: in function `TPRegexp::~TPRegexp()':
TPRegexp.cxx:(.text+0x745): undefined reference to `pcre_free'
/usr/bin/ld: TPRegexp.cxx:(.text+0x75e): undefined reference to `pcre_free'
/usr/bin/ld: CMakeFiles/Core.dir/base/src/TPRegexp.cxx.o: in function `TPRegexp::Compile()':
TPRegexp.cxx:(.text+0x910): undefined reference to `pcre_free'
/usr/bin/ld: TPRegexp.cxx:(.text+0x977): undefined reference to `pcre_compile'
/usr/bin/ld: CMakeFiles/Core.dir/base/src/TPRegexp.cxx.o: in function `TPRegexp::SubstituteInternal(TString&, TString const&, int, int, bool) const':
TPRegexp.cxx:(.text+0xe5f): undefined reference to `pcre_exec'
collect2: error: ld returned 1 exit status
make[2]: *** [core/CMakeFiles/Core.dir/build.make:2885: lib/libCore.so] Error 1
make[1]: *** [CMakeFiles/Makefile2:39210: core/CMakeFiles/Core.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
-- clad build command succeeded.  See also /home/dragon/github/root2/root_build/interpreter/cling/tools/plugins/clad/clad-prefix/src/clad-stamp/clad-build-*.log
[ 77%] Performing install step for 'clad'
-- clad install command succeeded.  See also /home/dragon/github/root2/root_build/interpreter/cling/tools/plugins/clad/clad-prefix/src/clad-stamp/clad-install-*.log
[ 77%] Completed 'clad'
[ 77%] Built target clad
make: *** [Makefile:152: all] Error 2

Setup

ROOT v6.32.04
Built for linuxx8664gcc on Aug 15 2024, 15:50:24
From heads/latest-stable@
With c++ (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Binary directory: /home/dragon/github/root/root_install/bin

cmake_output.txt (13.7 KB)
install_output.txt (893.9 KB)

Additional context

Hello. I was trying to build ROOT from source and got this error.

As a workaround one can just use the built-in pcre, but this was a kinda obfuscated option that I eventually found after a couple hours of research.

This is why I decided to post it here in order to help others find the solution faster and to see if someone can help identifying why it is happening or why there was no error or warning about pcre installation.

so the steps to solve are:
1- Run cmake -DCMAKE_INSTALL_PREFIX=…/root_install …/root_src -Dbuiltin_pcre=ON
2- cmake --build . – install -j4

I’d like to know where to check for all the cmake options if thats possible!

Dear Javier,

Thanks for the post and welcome to the ROOT Community!
I am sorry to read that for your setup ROOT does not work out of the box.
For the Ubuntu 20 builds of our CI, we install on the containers the following pcre-related packages:

libpcre++-dev
libpcre3-dev

Can you check you also have them?
The philosophy we embraced is to rely as much as possible on system packages.

About your second question: here you can find the CMake options Building ROOT from source - ROOT .

As for the workaround of using the builtin pcre, it’s a good thought: that solution could be used while the real cause is understood.

Let us know how this goes.

Cheers,
D

Thank you Danilo for your response and for the warm welcome!

libpcre++-dev is already the newest version (0.9.5-6.1build1)

and

libpcre3-dev is already the newest version (2:8.39-12ubuntu0.1)

Indeed, I found this in the CMakeCache.txt:

//Path to a file.
PCRE2_INCLUDE_DIR:PATH=/usr/include

//Path to a library.
PCRE2_PCRE2_LIBRARY_DEBUG:FILEPATH=/usr/lib/x86_64-linux-gnu/libpcre2-8.so

//Path to a library.
PCRE2_PCRE2_LIBRARY_RELEASE:FILEPATH=/usr/lib/x86_64-linux-gnu/libpcre2-8.so
[...]
//Details about finding PCRE2
FIND_PACKAGE_MESSAGE_DETAILS_PCRE2:INTERNAL=[/usr/include][/usr/lib/x86_64-linux-gnu/libpcre2-8.so][v10.34()]

The issue is kind of weird, because pcre is found by cmake in usr/include and usr/lib and I checked and pcre_free is there obviously. Yet it fails at installation time. Do you have any other ideas on why this could happen?

I understand the philosophy of relying on system packages, but this looks like something that should toggle on the built-in pcre, instead of throwing an error.

Though by nature this looks like an issue that cannot be checked before making the build, right?

About your second question: here you can find the CMake options Building ROOT from source - ROOT .

I did miss that section on the docs, thank you!

Hi,

Thanks for investigating further.
It’s not clear to me whether with the right dependencies, you can build ROOT ok: can you clarify whether you have another problem?

Our builds seem to point to the fact that standard ubuntu20 + the necessary packages is enough to build ROOT and pass the entire testsuite.

Cheers,
D

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