pybind11 icon indicating copy to clipboard operation
pybind11 copied to clipboard

[BUG]: relocation R_X86_64_PC32 against symbol `_ZTV10ConfigFile' can not be used when making a shared object; recompile with -fPIC

Open yangxin6 opened this issue 2 years ago • 4 comments

Required prerequisites

  • [X] Make sure you've read the documentation. Your issue may be addressed there.
  • [X] Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
  • [x] Consider asking first in the Gitter chat room or in a Discussion.

What version (or hash if on master) of pybind11 are you using?

master

Problem description

When using cmake, the third-party library has interdependence and an error occurs. Looking forward to your reply.

Errors:

/usr/bin/ld: /home/xxx/lib/libobjMesh.a(objMesh.o): warning: relocation against `_ZTIi@@CXXABI_1.3' in read-only section `.text.unlikely'
 
/usr/bin/ld: /home/xxx/lib/libconfigFile.a(configFile.o): relocation R_X86_64_PC32 against symbol `_ZTV10ConfigFile' can not be used when making a shared object; recompile with -fPIC

Complete cmakelists:

cmake_minimum_required(VERSION 3.4...3.18)
project(corn_deformable)

SET(CMAKE_CXX_STANDARD 11)
SET(SOURCES src/main.cpp src/CornDeform.cpp)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)


add_subdirectory(pybind11)

INCLUDE_DIRECTORIES(
        ${PROJECT_SOURCE_DIR}/include
        ${PROJECT_SOURCE_DIR}/VEGA_FEM_4_0/include
)

LINK_DIRECTORIES(
        ${PROJECT_SOURCE_DIR}/VEGA_FEM_4_0/lib
)


pybind11_add_module(${PROJECT_NAME} ${SOURCES})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} PUBLIC
        -Wl,--start-group
        -lGL -lGLU -lglut -lGLEW
        libbasicAlgorithms.a
        libcamera.a
        libclothBW.a
        libconfigFile.a
        libconstrainedDOFs.a
        libcorotationalLinearFEM.a
        libforceModel.a
        libgetopts.a
        libgraph.a
        libimageIO.a
        libintegrator.a
        libintegratorSparse.a
        libinterpolationCoordinates.a
        libisotropicHyperelasticFEM.a
        liblighting.a
        liblistIO.a
        libmassSpringSystem.a
        libmatrixIO.a
        libmesh.a
        libminivector.a
        libobjMesh.a
        libopenGLHelper.a
        libperformanceCounter.a
        libpolarDecomposition.a
        libsceneObject.a
        libsparseMatrix.a
        libsparseSolver.a
        libstencilForceModel.a
        libstvk.a
        libvolumetricMesh.a
        -Wl,--end-group
        )


# EXAMPLE_VERSION_INFO is defined by setup.py and passed into the C++ code as a
# define (VERSION_INFO) here.
target_compile_definitions(${PROJECT_NAME}
                           PRIVATE VERSION_INFO=${EXAMPLE_VERSION_INFO})

Reproducible example code

No response

Is this a regression? Put the last known working version here if it is.

Not a regression

yangxin6 avatar Jan 13 '23 09:01 yangxin6

I confirm the issue, reproducible example can be found here

anstadnik avatar May 13 '23 07:05 anstadnik

Interestingly, for my particular case it got fixed by using a conda's compiler. Originaly, my local compiler (GNU 13.1.1) was used. After I used conda's (GNU 11.3.0), the issue was fixed.

anstadnik avatar May 13 '23 07:05 anstadnik

Not sure if this is helpful for your setup, but for anyone also compiling cpp files in the cmake. I added SHARED to add_library and it worked.

For example:

add_library(${PROJECT_NAME} SHARED
  src/datastructures/Graph.cpp
  src/datastructures/SearchQueue.cpp
  src/datastructures/State.cpp
)

schmittlema avatar Dec 23 '23 12:12 schmittlema