其他分享
首页 > 其他分享> > undefined symbol的一种解决方案(g++)

undefined symbol的一种解决方案(g++)

作者:互联网

g++生成动态链接库的时候,参数的位置,也会影响到最后的结果,慎重。 把需要编译的源文件放在第一个参数的位置,可以解决莫名其妙的undefined symbol的问题。   例如,这个命令行会导致问题。 g++ -shared -fPIC -I ./server/ -I ./server/ctp_api_6.3.15_20190220/ -L ./server/ctp_api_6.3.15_20190220/linux64/ -lthostmduserapi_se -lthosttraderapi_se -lpthread ./server/cpp_ctp.cpp -o cpp_ctp.so

ldd -r cpp_ctp.so
linux-vdso.so.1 (0x00007fffe9588000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f77651a6000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7764f8e000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7764b9d000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f77647ff000)
/lib64/ld-linux-x86-64.so.2 (0x00007f77657bb000)
undefined symbol: pthread_create (./cpp_ctp.so)
undefined symbol: _ZN15CThostFtdcMdApi15CreateFtdcMdApiEPKcbb (./cpp_ctp.so)
undefined symbol: _ZN19CThostFtdcTraderApi13GetApiVersionEv (./cpp_ctp.so)
undefined symbol: _ZN15CThostFtdcMdApi13GetApiVersionEv (./cpp_ctp.so)
undefined symbol: _ZN19CThostFtdcTraderApi19CreateFtdcTraderApiEPKc (./cpp_ctp.so)

下面的命令行可以正常工作。

g++ ./server/cpp_ctp.cpp -shared -fPIC -I ./server/ -I ./server/ctp_api_6.3.15_20190220/ -L ./server/ctp_api_6.3.15_20190220/linux64/ -lthostmduserapi_se -lthosttraderapi_se -lpthread  -o cpp_ctp.so

ldd -r cpp_ctp.so
linux-vdso.so.1 (0x00007ffcc65dd000)
libthostmduserapi_se.so => ./server/ctp_api_6.3.15_20190220/linux64/libthostmduserapi_se.so (0x00007ff2252a7000)
libthosttraderapi_se.so => ./server/ctp_api_6.3.15_20190220/linux64/libthosttraderapi_se.so (0x00007ff22493b000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff22471c000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007ff224393000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007ff22417b000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff223d8a000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007ff223b82000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff22397e000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ff2235e0000)
/lib64/ld-linux-x86-64.so.2 (0x00007ff225e1d000)

标签:ctp,undefined,++,symbol,64,linux,cpp,so,x86
来源: https://www.cnblogs.com/zhsmtp/p/13069241.html