简体   繁体   中英

Relocation R_X86_64_PC32 against undefined hidden symbol `__dso_handle' can not be used when making a shared object

I want to use C++ functions in Python. Thus, I decided to try to use SWIG for that purpose. At first, I run command:

swig -python test.i

Then compile it with g++-6.2 as follows:

g++-6.2 -c test.cpp test_wrap.c -fPIC -I /usr/include/python3.6m

To this moment everything works fine, but the problem occurs at the last step when linking must be created. I run command :

ld -shared test.o test_wrap.o -o _test.so

As suggested in Swig tutorial , but I recieve a following error:

test.o: In function `__static_initialization_and_destruction_0(int, int)':
test.cpp:(.text+0x66): undefined reference to `__dso_handle'
ld: test.o: relocation R_X86_64_PC32 against undefined hidden symbol `__dso_handle' can not be used when making a shared object
ld: final link failed: Bad value

Does anyone know how to fix this?

You don't link with the ld command. You link with the same $(CC) or $(CXX) ( gcc or g++ ) you compile with, using options appropriate for linking. It will drive the backend linker ld with the right command line options for the ABI, target format, etc. that should be generated.

Do this and it should work fine:

g++-6.2 -shared test.o test_wrap.o -o _test.so

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM