TWS API Linux - 分段错误 - __bid64_to_string

And*_*man 2 c++ linux gcc c++11

开箱即用地运行 Cpp 示例客户端。

\n

我收到分段错误。

\n

0x00005555555efba6 in __bid64_to_string ()

\n

已将此函数来源到客户端文件Decimal.h

\n

extern "C" void __bid64_to_string(char*, Decimal, unsigned int*);

\n

这可能与API文档提到的浮点库有关:Intel\xc2\xae Decimal Floating-Point Math Library

\n

https://interactivebrokers.github.io/tws-api/introduction.html

\n

我已经使用 WSL Ubuntu 20.04.05 检查了它是否安装在我的 ubuntu 版本上

\n
libintelrdfpmath-dev/now 2.0u2-4 amd64 [installed,local]\n\nroot@flare9x:~# dpkg -s libintelrdfpmath-dev\nPackage: libintelrdfpmath-dev\nStatus: install ok installed\nPriority: optional\nSection: libdevel\nInstalled-Size: 72286\nMaintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>\nArchitecture: amd64\nSource: intelrdfpmath\nVersion: 2.0u2-4\nDescription: Intel Decimal Floating-Point Math Library\n Software implementation of the IEEE 754-2008 Decimal Floating-Point\n Arithmetic specification, aimed at financial applications, especially\n in cases where legal requirements make it necessary to use decimal, and\n not binary floating-point arithmetic (as computation performed with\n binary floating-point operations may introduce small, but unacceptable\n errors).\nOriginal-Maintainer: Christian Stalp <chris@chrishell.de>\nHomepage: https://software.intel.com/en-us/articles/intel-decimal-floating-point-math-library\n\n\n
Run Code Online (Sandbox Code Playgroud)\n

查看makefile:

\n
CXXFLAGS=-pthread -Wall -Wno-switch -Wpedantic -Wno-unused-function -std=c++11\nROOT_DIR=../../../source/cppclient\nBASE_SRC_DIR=${ROOT_DIR}/client\nINCLUDES=-I${BASE_SRC_DIR} -I${ROOT_DIR}\nSHARED_LIB_DIRS=${BASE_SRC_DIR}\nSHARD_LIBS=libTwsSocketClient.so\nTARGET=TestCppClient\n\n$(TARGET)Static:\n    $(CXX) $(CXXFLAGS) $(INCLUDES) $(BASE_SRC_DIR)/*.cpp ./*.cpp $(BASE_SRC_DIR)/lib/libbid.a -o$(TARGET)Static\n\n$(TARGET):\n    $(CXX) $(CXXFLAGS) $(INCLUDES) ./*.cpp $(BASE_SRC_DIR)/lib/libbid.so $(SHARED_LIB_DIRS)/$(SHARD_LIBS) -o$(TARGET)\n\nclean:\n    rm -f $(TARGET) $(TARGET)Static *.o\n\n
Run Code Online (Sandbox Code Playgroud)\n

有趣的部分 - 我可以在 Windows 上编译完全相同的代码,在 win32 中编译 VScode。

\n

我尝试用 gcc 强制执行 32 位。添加-m32。

\n

执行此操作时,编译器会显示许多抱怨:

\n
 1974 |  printf("Soft dollar tiers (%lu):", tiers.size());\n      |                             ~~^     ~~~~~~~~~~~~\n      |                               |               |\n      |                               |               std::vector<SoftDollarTier>::size_type {aka unsigned int}\n      |                               long unsigned int\n      |                             %u\n
Run Code Online (Sandbox Code Playgroud)\n

我注释掉了这些包含 %lu 的函数,因为在主应用程序中不需要它们。

\n

再次编译,这次我们与 TWS API 一起打包的库(英特尔十进制浮点数学库)出现错误,这些库随原始 TWS 安装一起提供,并定位:

\n
/source/cppclient/client/lib/libbid.a\n
Run Code Online (Sandbox Code Playgroud)\n
/usr/bin/ld: i386:x86-64 architecture of input file `../../../source/cppclient/client/lib/libbid.a(bid64_string.o)\' is incompatible with i386 output\n/usr/bin/ld: i386:x86-64 architecture of input file `../../../source/cppclient/client/lib/libbid.a(bid128_2_str_tables.o)\' is incompatible with i386 output\n/usr/bin/ld: i386:x86-64 architecture of input file `../../../source/cppclient/client/lib/libbid.a(bid_decimal_data.o)\' is incompatible with i386 output\n
Run Code Online (Sandbox Code Playgroud)\n

win32 运行这个 vscode 就很好了。

\n

使用 ```gcc -m64`` 运行

\n

再次获取段错误:

\n
Thread 1 "TestCppClientSt" received signal SIGSEGV, Segmentation fault.\n0x00005555555efba6 in __bid64_to_string ()\n(gdb) bt\n#0  0x00005555555efba6 in __bid64_to_string ()\n#1  0x00007fffffffd940 in ?? ()\n#2  0x00007fffffffd940 in ?? ()\n#3  0x00007fffffffd940 in ?? ()\n#4  0x00007fffffffd941 in ?? ()\n#5  0x00007fffffffd940 in ?? ()\n#6  0x00007fffffffd820 in ?? ()\n#7  0x000055555555d5ff in std::iterator_traits<char*>::difference_type std::distance<char*>(char*, char*) ()\nBacktrace stopped: previous frame inner to this frame (corrupt stack?)\n
Run Code Online (Sandbox Code Playgroud)\n

不确定此时可能是什么 - WSL 和在 Windows 上运行 ubuntu - 该进程管理内存?ubuntu和windows有冲突吗?

\n

此时 - 我还能检查/排除哪些问题?

\n

谢谢

\n

And*_*man 5

好吧,终于找到了英特尔浮点数学库所在的位置(名为:)libintelrdfpmath-dev,这与按原样使用 TWS API 附带的库(位于目录:)形成鲜明对比~/IBJts/source/cppclient/client/lib/libbid.a

 root@Ubuntu-22:/bin# dpkg -L libintelrdfpmath-dev
/.
/usr
/usr/include
/usr/include/bid_conf.h
/usr/include/bid_functions.h
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/libbidgcc000.a
/usr/lib/x86_64-linux-gnu/libbidgcc000b.a
/usr/lib/x86_64-linux-gnu/libbidgcc001.a
/usr/lib/x86_64-linux-gnu/libbidgcc001b.a
/usr/lib/x86_64-linux-gnu/libbidgcc010.a
/usr/lib/x86_64-linux-gnu/libbidgcc010b.a
/usr/lib/x86_64-linux-gnu/libbidgcc011.a
/usr/lib/x86_64-linux-gnu/libbidgcc011b.a
/usr/lib/x86_64-linux-gnu/libbidgcc100.a
/usr/lib/x86_64-linux-gnu/libbidgcc100b.a
/usr/lib/x86_64-linux-gnu/libbidgcc101.a
/usr/lib/x86_64-linux-gnu/libbidgcc101b.a
/usr/lib/x86_64-linux-gnu/libbidgcc110.a
/usr/lib/x86_64-linux-gnu/libbidgcc110b.a
/usr/lib/x86_64-linux-gnu/libbidgcc111.a
/usr/lib/x86_64-linux-gnu/libbidgcc111b.a
/usr/share
/usr/share/doc
/usr/share/doc/libintelrdfpmath-dev
/usr/share/doc/libintelrdfpmath-dev/README.gz
/usr/share/doc/libintelrdfpmath-dev/changelog.Debian.gz
/usr/share/doc/libintelrdfpmath-dev/copyright
Run Code Online (Sandbox Code Playgroud)

我编辑了makefile该库的路径,现在是哪个?

我添加了

/usr/lib/x86_64-linux-gnu/libbidgcc000.a到我的 make 文件。

我的 makefile 如下所示:

CXX=g++
CXXFLAGS=-pthread -Wall -Wno-switch -Wpedantic -Wno-unused-function -std=c++11
ROOT_DIR=../../../source/cppclient
BASE_SRC_DIR=${ROOT_DIR}/client
INCLUDES=-I${BASE_SRC_DIR} -I${ROOT_DIR}
SHARED_LIB_DIRS=${BASE_SRC_DIR}
SHARD_LIBS=libTwsSocketClient.so
TARGET=TestCppClient

$(TARGET)Static:
$(CXX) $(CXXFLAGS) $(INCLUDES) $(BASE_SRC_DIR)/*.cpp ./*.cpp /usr/lib/x86_64-linux-gnu/libbidgcc000.a -o$(TARGET)Static

$(TARGET):
$(CXX) $(CXXFLAGS) $(INCLUDES) ./*.cpp $(BASE_SRC_DIR)/lib/libbid.so $(SHARED_LIB_DIRS)/$(SHARD_LIBS) -o$(TARGET)

clean:
rm -f $(TARGET) $(TARGET)Static *.o

Run Code Online (Sandbox Code Playgroud)

请求的实时条形图、小数位看起来符合预期,最重要的是没有分段错误。

RealTimeBars. 3001 - Time: 1673241105, Open: 0.87948, High: 0.87951, Low: 0.87947, Close: 0.87951, Volume: -1, Count: -1, WAP: -1
Run Code Online (Sandbox Code Playgroud)

希望这能解决其他问题。