Reputation: 1239
I have following code:
#include <iostream>
extern "C" {
void foo() {
std::cout << "Wow, It's working!" << std::endl;
}
}
Without inclusion of iostream and printing the library links correctly. But when I include and try to print, compiler gives me following errors:
Compiling: main.cpp
Linking dynamic library: libfoo.so
/usr/bin/ld: obj/main.o: перемещение R_X86_64_32 для «.rodata» не может использоваться при создании общего объекта; перекомпилируйте с -fPIC
obj/main.o: could not read symbols: Некорректное значение
collect2: ошибка: выполнение ld завершилось с кодом возврата 1
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings
Sorry for the errors in Russian, but I have no exact translation into English. Maybe this translation will help:
Compiling: main.cpp
Linking dynamic library: libfoo.so
/usr/bin/ld: obj/main.o: relocation R_X86_64_32 against ".rodata" can not be used when making shared object; recompile with -fPIC
obj/main.o: could not read symbols: bad value
collect2: error: ld terminated with exit code 1
Process terminated with status 1 (0 minutes, 0 seconds)
0 errors, 0 warnings
How I must include and compile to get it working?
P.S. The grammar can be very bad: English is not my native language
Upvotes: 0
Views: 611
Reputation: 10729
Have you tried -lstdc++
linker switch? How does your makefile look like?
Upvotes: 1