I am using the function regcomp() in my code. My code links with libonig.so as well as libc.so.6. Both these libraries have their own implementations of regcomp(), however I want to use the implementation from libonig.so. However, my code always uses the implementation from libc.so.6. The output of ldd is as follows -
开发者_运维技巧ldd libtest.so
linux-vdso.so.1 => (0x00007fffa03ff000)
libonig.so.2 => /usr/local/lib/libonig.so.2 (0x00007f5cb2fbf000)
libstdc++.so.6 => /usr/local/lib64/libstdc++.so.6 (0x00007f12a43cf000)
libm.so.6 => /lib64/libm.so.6 (0x00007f12a414c000)
libgcc_s.so.1 => /usr/local/lib64/libgcc_s.so.1 (0x00007f12a3f36000)
libc.so.6 => /lib64/libc.so.6 (0x00007f12a3be1000)
/lib64/ld-linux-x86-64.so.2 (0x0000003421c00000)
I am not allowed to modify any of the libonig.so or libc.so.6. Is there a way to specify to the linker that regcomp() should be used from libonig.so?
Just solved this issue. I was actually using dlopen() to load a shared object (libtest.so). So I should have linked libonig.so to the binary that was loading libtest.so.
On the other hand, I was trying to link libonig.so to libtest.so. However when the binary ran, it got its version of regcomp() from libc.so.6 and did not consider it necessary to resolve the symbol with libonig.so. Linking libonig.so and including its path in LD_LIBRARY_PATH solved the problem.
精彩评论