Minimum reproducible example:
// dynamic.hpp
class Test {
private:
static void update();
};
// dynamic.cpp
#include "dynamic.hpp"
#include <iostream>
void Test::update() {
std::cout << "Hello World!" << std::endl;
}
If I try to build this using c++ -shared dynamic.cpp it fails:
/usr/bin/ld: /tmp/ccmTgJfw.o: warning: relocation against `_ZSt4cout@@GLIBCXX_3.4' in read-only section `.text'
/usr/bin/ld: /tmp/ccmTgJfw.o: relocation R_X86_64_PC32 against symbol `_ZSt4cout@@GLIBCXX_3.4' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
I do not have much experience with the linker and would like to understand what is going on here and why that does not work.