#1054538 libboost-regex-dev: the static library should be compile with -PIC

Package:
libboost-regex-dev
Source:
libboost-regex-dev
Description:
regular expression library for C++ (default version)
Submitter:
Frantisek Boranek
Date:
2023-10-25 10:42:04 UTC
Severity:
normal
#1054538#5
Date:
2023-10-25 10:39:40 UTC
From:
To:
Dear Maintainer,

I wanted compile fat dynamic library with all its dependencies linked static and hidden symbols.

Let demonstrate on example:

```CMake
set(Boost_VERBOSE ON)
set(Boost_USE_STATIC_LIBS ON)
find_package(Boost REQUIRED COMPONENTS regex)

# library
add_library(lib_r SHARED lib_r.cc)
target_link_libraries(lib_r PRIVATE Boost::regex)

# executable
add_executable(test_r main_r.cc)
target_link_libraries(test_r PRIVATE lib_r)
```

with `set(Boost_USE_STATIC_LIBS ON)` is find static version of library

```
-- Found boost_regex 1.74.0 at /usr/lib/x86_64-linux-gnu/cmake/boost_regex-1.74.0
--   [ ] libboost_regex.so.1.74.0
--   [x] libboost_regex.a
```

and linking of shared library fails on:
```
[ 50%] Linking CXX shared library liblib_r.so
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libboost_regex.a(regex.o): warning: relocation against `_ZTVN5boost10wrapexceptISt11logic_errorEE' in read-only section `.text.unlikely'
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libboost_regex.a(instances.o): relocation R_X86_64_PC32 against symbol `_ZTVSt15basic_streambufIcSt11char_traitsIcEE@@GLIBCXX_3.4' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
```

full example: https://github.com/fboranek/boost-static

I think that even static library `libboost_regex.a` should be built with position independent code flag `-PIC`. I try the same for `Boost::thread` with the same result, so it apply probably on whole boost.

I try compile boost directly
```
./bootstrap.sh --with-libraries=regex
./b2 link=static runtime-link=shared
```

and replace `Boost::regex` by `boost/stage/lib/libboost_regex.a` and library and executable is liked witout issue. In light of this it seems the problem with packaging. I clone latest boost repo.

BR,
Frantisek