英文:
TWS API Linux - Segmentation fault - __bid64_to_string
问题
以下是翻译好的部分:
我在不做任何修改的情况下运行C++示例客户端。
我收到了一个分段错误。
我将此函数源代码放到客户端文件的“Decimal.h”中。
这可能与API文档提到的浮点库有关:Intel® Decimal Floating-Point Math Library
我已经检查了我的Ubuntu版本是否安装了这个库,使用的是WSL Ubuntu 20.04.05。
看一下Makefile:
有趣的部分是,我可以在Windows上的VSCode中编译完全相同的代码。
我已经尝试使用gcc强制使用32位。添加了-m32。
当这样做时,编译器会显示大量的警告。
我已经注释掉了包含%lu的这些函数,因为在主应用程序中不需要它们。
再次编译,这次我们遇到了打包在TWS API中的库的问题 - Intel十进制浮点数数学库,这些库随原始TWS安装一起提供,并位于:
/source/cppclient/client/lib/libbid.a
/usr/bin/ld:输入文件“../../../source/cppclient/client/lib/libbid.a(bid64_string.o)”的i386:x86-64架构与i386输出不兼容
/usr/bin/ld:输入文件“../../../source/cppclient/client/lib/libbid.a(bid128_2_str_tables.o)”的i386:x86-64架构与i386输出不兼容
/usr/bin/ld:输入文件“../../../source/cppclient/client/lib/libbid.a(bid_decimal_data.o)”的i386:x86-64架构与i386输出不兼容
win32在VSCode中可以正常运行。
使用“gcc -m64”运行时再次出现分段错误:
线程1“TestCppClientSt”接收到信号SIGSEGV,分段错误。
不确定此时可能是什么问题 - WSL和在Windows上运行的Ubuntu - 这个过程如何管理内存?是Ubuntu与Windows冲突。
在这一点上,还可以检查/排除什么?
谢谢。
英文:
Running Cpp sample client out of the box.
I receive a segmentation fault.
0x00005555555efba6 in __bid64_to_string ()
Have sourced this function to client file to Decimal.h
extern "C" void __bid64_to_string(char*, Decimal, unsigned int*);
This may have something to do with the floating point library that the API documentation mentions: Intel® Decimal Floating-Point Math Library
https://interactivebrokers.github.io/tws-api/introduction.html
I have checked if this is installed on my ubuntu version, using WSL Ubuntu 20.04.05
libintelrdfpmath-dev/now 2.0u2-4 amd64 [installed,local]
root@flare9x:~# dpkg -s libintelrdfpmath-dev
Package: libintelrdfpmath-dev
Status: install ok installed
Priority: optional
Section: libdevel
Installed-Size: 72286
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Source: intelrdfpmath
Version: 2.0u2-4
Description: Intel Decimal Floating-Point Math Library
Software implementation of the IEEE 754-2008 Decimal Floating-Point
Arithmetic specification, aimed at financial applications, especially
in cases where legal requirements make it necessary to use decimal, and
not binary floating-point arithmetic (as computation performed with
binary floating-point operations may introduce small, but unacceptable
errors).
Original-Maintainer: Christian Stalp <chris@chrishell.de>
Homepage: https://software.intel.com/en-us/articles/intel-decimal-floating-point-math-library
Looking at the makefile:
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 $(BASE_SRC_DIR)/lib/libbid.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
The interesting part - I can compile the exact same code on Windows, VScode in win32.
I have tried to enforce 32bit with gcc. adding -m32.
When doing this compiler shows numerous complaints:
1974 | printf("Soft dollar tiers (%lu):", tiers.size());
| ~~^ ~~~~~~~~~~~~
| | |
| | std::vector<SoftDollarTier>::size_type {aka unsigned int}
| long unsigned int
| %u
I commented out these functions which include %lu as do not need them in main application.
Compile again, this time we have errors with the librarys that are packaged with the TWS API - the Intel decimal floating point math library, these libs come with the original TWS installation and locate:
/source/cppclient/client/lib/libbid.a
/usr/bin/ld: i386:x86-64 architecture of input file `../../../source/cppclient/client/lib/libbid.a(bid64_string.o)' is incompatible with i386 output
/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
/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
win32 runs this just fine vscode.
running with ```gcc -m64``
Obtain seg fault again:
Thread 1 "TestCppClientSt" received signal SIGSEGV, Segmentation fault.
0x00005555555efba6 in __bid64_to_string ()
(gdb) bt
#0 0x00005555555efba6 in __bid64_to_string ()
#1 0x00007fffffffd940 in ?? ()
#2 0x00007fffffffd940 in ?? ()
#3 0x00007fffffffd940 in ?? ()
#4 0x00007fffffffd941 in ?? ()
#5 0x00007fffffffd940 in ?? ()
#6 0x00007fffffffd820 in ?? ()
#7 0x000055555555d5ff in std::iterator_traits<char*>::difference_type std::distance<char*>(char*, char*) ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
Not sure what it could be at this point - WSL and running ubuntu on windows - that process manages memory? is ubuntu clashing with windows.
At this point - what else can I check / troubleshoot?
Thanks
答案1
得分: 3
好的,最终成功了,通过定位英特尔浮点数数学库的位置,名为: libintelrdfpmath-dev
,与使用TWS API提供的默认库相对,它位于目录: ~/IBJts/source/cppclient/client/lib/libbid.a
。
我编辑了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
请求实时K线图,小数位数看起来是预期的,最重要的是没有分段错误。
RealTimeBars. 3001 - 时间: 1673241105, 开盘价: 0.87948, 最高价: 0.87951, 最低价: 0.87947, 收盘价: 0.87951, 成交量: -1, 计数: -1, WAP: -1
希望这解决了其他人的问题。
英文:
Ok finally got it working by locating where the intel floating point math library was located, named: libintelrdfpmath-dev
, this was in contrast to using the library that comes with the TWS API as is, located at directory: ~/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
I edited the makefile
to include the path to this library, now which one?
I added
/usr/lib/x86_64-linux-gnu/libbidgcc000.a
to my make file.
My makefile looks like:
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
requested real time bars, decimal places looks as intended and most of all no segmentation fault.
RealTimeBars. 3001 - Time: 1673241105, Open: 0.87948, High: 0.87951, Low: 0.87947, Close: 0.87951, Volume: -1, Count: -1, WAP: -1
hopefully this solves others issues with this.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论