Ошибка связывания protobuf.a с кодом на c++

Пишу приложение, которое использует protobuf, все успешно запускается и линкуется на манджаре,так как protobuf стоит как .so, запускаю ранер на astra 1.7, там вылезает ошибка при секции билд.

: && /usr/bin/clang++     CMakeFiles/testApp.dir/src/c++/main.cc.o CMakeFiles/testApp.dir/test.grpc.pb.cc.o CMakeFiles/testApp.dir/test.pb.cc.o  -o testApp  /usr/local/lib/libprotobuf.a  -lpthread && :
/usr/bin/ld: /usr/local/lib/libprotobuf.a(arena.cc.o): relocation R_X86_64_32 against symbol `_ZN6google8protobuf8internal9ArenaFreeEPvm' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /usr/local/lib/libprotobuf.a(arenastring.cc.o): relocation R_X86_64_32 against symbol `__pthread_key_create@@GLIBC_2.2.5' can not be used when making a PIE object; recompile with -fPIC

CMakeLists.txt

cmake_minimum_required(VERSION 3.15.0)

include_guard(GLOBAL)

project(testApp
  VERSION 0.0.1
  DESCRIPTION "examples CMake for Proto and gRPC"
  HOMEPAGE_URL www.uav.radar-mms.com/gitlab
  LANGUAGES C CXX
)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set_target_properties( PROPERTIES
  CXX_STANDARD 20
  CXX_STANDARD_REQUIRED ON
  CXX_EXTENSIONS OFF
  POSITION_INDEPENDENT_CODE ON
)

include(FindProtobuf)
find_package(gRPC REQUIRED)
find_package(Protobuf REQUIRED CONFIG)
find_package(Python3)
include_directories(${Protobuf_INCLUDE_DIRS})

message(STATUS "[${PROJECT_NAME}] generating protobuf files...")
message(STATUS "[${PROJECT_NAME}] command: ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate-protobufs.py")

execute_process(
        COMMAND
        ${Python3_EXECUTABLE}
        ${CMAKE_CURRENT_SOURCE_DIR}/scripts/generate-protobufs.py
        --target ${CMAKE_CURRENT_BINARY_DIR}
        --proto ${CMAKE_CURRENT_SOURCE_DIR}/src/proto
        --name ${PROJECT_NAME}
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

file(GLOB PROTO_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}/protobufs/*.h")
file(GLOB PROTO_SOURCES "${CMAKE_CURRENT_BINARY_DIR}/*.pb.cc")
set(PROTO_HEADER_PATH_B "${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}/protobufs")
set(PROTO_HEADER_PATH_I "include/${PROJECT_NAME}/protobufs")
message(STATUS "[${PROJECT_NAME}] protobuf headers: ${PROTO_HEADERS}")
message(STATUS "[${PROJECT_NAME}] protobuf sources: ${PROTO_SOURCES}")

add_executable(${PROJECT_NAME})
target_compile_options(${PROJECT_NAME} PRIVATE -fPIC)

target_sources(${PROJECT_NAME}
  PUBLIC
    $<BUILD_INTERFACE:${PROTO_HEADER_PATH_B}/test.pb.h> $<INSTALL_INTERFACE:${PROTO_HEADER_PATH_I}/test.pb.h>
    $<BUILD_INTERFACE:${PROTO_HEADER_PATH_B}/test.grpc.pb.h> $<INSTALL_INTERFACE:${PROTO_HEADER_PATH_I}/test.grpc.pb.h>
  PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}/src/c++/main.cc
    ${PROTO_SOURCES}
)

target_link_libraries(${PROJECT_NAME}
    PRIVATE
    ${Protobuf_LIBRARIES}
)

if (Protobuf_VERSION VERSION_GREATER_EQUAL 4)
  target_link_libraries (${PROJECT_NAME}
          PUBLIC
          absl::log_internal_check_op
  )
endif ()


target_include_directories(${PROJECT_NAME}
  PUBLIC
    $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
    $<INSTALL_INTERFACE:include>
  PRIVATE
    ${PROTO_HEADER_PATH_B}
    ${CMAKE_CURRENT_SOURCE_DIR}/src
    ${CMAKE_CURRENT_SOURCE_DIR}/src/c++
)

Используется protobuf версии 3.14.

Прочитал, чтобы это поправить, надо самому собрать protobuf с флагом -fPIC, но я бы не хотел это делать, можно ли как-то по другому исправить?


Ответы (0 шт):