I'm compiling a c++ program using the command line
g++ -c prog.cc -std=c++11 -march=native -fPIC -fopenmp
and then try to make a shared object via
g++ prog.o -shared -fopenmp -o lib/libprog.so
This has always worked. But today I get:
/usr/bin/ld: prog.o: relocation R_X86_64_PC32 against undefined symbol
`_ZTVN12_GLOBAL__N_111handle_baseE' can not be used when making a shared
object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status
The symbol _ZTVN12_GLOBAL__N_111handle_baseE
de-mangles to
vtable for (anonymous namespace)::handle_base
(handle_base
is a polymorphic class defined in the anonymous namespace in prog.cc and yes I do call dynamic_cast<handle_base>()
.)
I'm using gcc version 4.7.0 (GCC) and GNU ld (GNU Binutils; openSUSE 11.1) 2.19. Can anybody help (suggest solutions [other than doing without shared object or the dynamic cast
])?
I just ran into something similar when upgrading to ubuntu 14.04. I had to add -fkeep-inline-functions to the source file that defined the 'missing' symbol. No idea if your problem is similar.