I have a program that dlopen a .so library I made that uses another .so libary
- my program (that uses libctp.so by dlopen at runtime)
- libctp.so (that I made)
- thostmduserapi.so (made by others, libctp.so uses it)
but when it runs, it shows this error:
symbol lookup error: ./libctp.so: undefined symbol: _ZN15CThostFtdcMdApi15CreateFtdcMdApiEPKcbb
Then I found out my .so doesn't actually link with another .so I used ldd to examine it:
$ldd libctp.so
linux-vdso.so.1 => (0x00007fff2b7db000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f736b082000)
/lib64/ld-linux-x86-64.so.2 (0x00007f736b649000)
no thostmduserapi.so there! It doesn't make scene to me, so I tried to NOT using GYP to generate the makefile. Instead, I type command by hand to compile it as below:
$ g++ -fPIC -shared main.cpp -l:thostmduserapi.so -Wl,-rpath,. -o libctp.so
It works!
$ ldd libctp.so
linux-vdso.so.1 => (0x00007ffc0f6cb000)
thostmduserapi.so (0x00007fb3cde36000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fb3cda71000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fb3cd853000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fb3cd64b000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fb3cd447000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fb3cd143000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fb3cce3d000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fb3ccc27000)
/lib64/ld-linux-x86-64.so.2 (0x00007fb3ce5dd000)
thostmduserapi.so is there!!
But how come makefile generated by GYP doesn't link with thostmduserapi.so!?? It seems very strange to me. Does anyone know what happen to GYP's project?
Thanks in advance for your help!
Here is my GYP file:
{
'targets': [
{
'target_name': 'ctp',
'type': 'shared_library',
'include_dirs': [
'../../../',
],
'sources': [
'main.cpp',
],
'product_dir': '../../../deploy',
'ldflags': [
'-l:thostmduserapi.so',
'-L../../../third_party/ctp/linux64',
'-Wl,-rpath,.',
],
'cflags': [
'-fPIC',
'-std=c++11',
],
},
],
}
Here is the code of my .so library
#include <third_party/ctp/linux64/include/ThostFtdcMdApi.h>
#include <stdio.h>
void* get_exchange_api(){
printf("test\n");
CThostFtdcMdApi::CreateFtdcMdApi(); // <-- function in thostmduserapi.so
return 0;
}