title: relocation R_X86_64_PC32 against symbol can not be used when making a shared object when fPIC was already used
body: <p>I have looked at numerous posts regarding resolving this type of linker error, in most cases, people just forgot to compile with <code>-fPIC</code>, sometimes people had trouble with inline functions, etc. that is not the case here. I am trying to wrap a c++ library for python using <a href="https://pybind11.readthedocs.io" rel="nofollow noreferrer">Pybind11</a>. In this process, I want to link some static libraries (one of them is <a href="http://www.robertnz.net/nm11.htm" rel="nofollow noreferrer">newmat11</a>) into a .so file.</p>
  <p>I build the newmat11 library using an automake system with <code>-fPIC</code> (here's some output...)</p>
  <pre><code>...
  g++ -DHAVE_CONFIG_H -I. -g -O2 -MT newmat8.lo -MD -MP -MF .deps/newmat8.Tpo -c newmat8.cpp  -fPIC -DPIC -o newmat8.o
  ...
  ar cru libnewmat11.a  bandmat.o cholesky.o evalue.o fft.o jacobi.o hholder.o myexcept.o newfft.o newmat1.o newmat2.o newmat3.o newmat4.o newmat5.o newmat6.o newmat7.o newmat8.o newmat9.o newmatex.o newmatrm.o solution.o sort.o submat.o svd.o
  </code></pre>
  <p>Indeed, when I run <code>readelf --relocs libnewmat11.a</code>, I see plenty of relocated symbols. Here's one that's giving me trouble:</p>
  <pre><code>$readelf --relocs libnewmat11.a | grep ZTIN6NEWMAT17Sing
  000000001d20  013c00000002 R_X86_64_PC32     0000000000000000 _ZTIN6NEWMAT17Singular - 4
  Relocation section '.rela.data.rel.ro._ZTIN6NEWMAT17SingularExceptionE' at offset 0x21280 contains 3 entries:
  000000005b0b  013c00000001 R_X86_64_64       0000000000000000 _ZTIN6NEWMAT17Singular + 0
  0000000009fc  008d00000002 R_X86_64_PC32     0000000000000000 _ZTIN6NEWMAT17Singular - 4
  Relocation section '.rela.data.rel.ro._ZTIN6NEWMAT17SingularExceptionE' at offset 0x20b38 contains 3 entries:
  000000008280  008d00000001 R_X86_64_64       0000000000000000 _ZTIN6NEWMAT17Singular + 0
  ...
  </code></pre>
  <p>Everything seems ok so far, but when I run <code>python3 setup.py build</code> I get this error:</p>
  <pre><code>running build
  running build_py
  running build_ext
  building 'mytest' extension
  x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I../.. -I../../mhfe -I/usr/include/python3.8 -I/usr/local/include/newmat11/include -c src/my_python_binding.cpp -o build/temp.linux-x86_64-3.8/src/my_python_binding.o -std=c++11 -DPYBIND11_PYTHON_VERSION=3.8
  ...
  x86_64-linux-gnu-g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.8/src/my_python_binding.o -L/usr/lib64python3.8 -o build/lib.linux-x86_64-3.8/mytest.cpython-38-x86_64-linux-gnu.so -fPIC -Wl,--whole-archive /usr/local/lib/newmat11/lib/libnewmat11.a -Wl,--no-whole-archive
  /usr/bin/ld: /usr/local/lib/newmat11/lib/libnewmat11.a(newmat8.o): relocation R_X86_64_PC32 against symbol `_ZTIN6NEWMAT17SingularExceptionE' can not be used when making a shared object; recompile with -fPIC
  
  </code></pre>
  <p>As noted above, I'm building the static lib with <code>-fPIC</code> and I can see the relocation symbols in the <code>.a</code> file. Is there something about <code>R_X86_64_PC32</code> that makes it incompatible with shared objects? I think I would need to have it produce <code>R_X86_64_PLT32</code> relocation symbols instead, but I'm really not sure. I can see other <code>R_X86_64_PLT32</code> relocation symbols in the library, but not for the symbol in question. Also, for the record, I'm not familiar with all of the flags that setuptools is adding to the build, perhaps one of them is giving me trouble?</p>
  <p>All help appreciated.</p>