課題
FIXエンジンをテストするためにFIXプロトコルで通信できるハンディなツールを作りたいので、ひとまずquickfixのpython libraryをインストールする。
実装
- python 3.12.5のみインストールした状態から始める
- venvを作り、そこにquickfixをインストールする
短いまとめ
- venv環境を作る
- MS Build toolをインストールする
- pip download quickfixでtar.gzファイルをダウンロードして展開する
- 展開先でsetup.py, stdafx.h, Utility.h を編集する
- pip install "展開先"でインストールする
失敗も含めた手順
venvで仮想環境を作る
C:\Users\user\git>py -m venv qfix
C:\Users\user\git>cd qfix
C:\Users\user\git\qfix>scripts\activate
(qfix) C:\Users\user\git\qfix>
quickfixをインストールする
(qfix) C:\Users\user\git\qfix>pip install quickfix
エラー画面に表示されているリンクからMS Build Toolをダウンロードしてインストール(デフォルトのバージョンが17.12.3だったのでそれをインストール)。Visual Studioや必要ないライブラリ等はインストールしたくなかったので以下の通りにインストール
再度pipすると、以下のfatal errorが出て失敗
...
test_std_tr1_shared_ptr.cpp(1): fatal error C1083: Cannot open include file: 'tr1/memory': No such file or directory
...
C++\Acceptor.cpp(21): fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
...
pipで直接インストールできなそうなのでいったんダウンロード
(qfix) C:\Users\user\git\qfix>pip download quickfix
venvフォルダ直下に展開(C:\Users\user\git\qfix\quickfix-1.15.1)
1番目のstd::tr1 namespaceはC++11時代のドラフト版のようなものとのことで、不要と判断。テスト用のファイルのようなので、展開先のsetup.pyの17~23行目をコメントアウト
## print("Testing for std::tr1::shared_ptr...")
## try:
## self.compiler.compile(['test_std_tr1_shared_ptr.cpp'])
## self.compiler.define_macro("HAVE_STD_TR1_SHARED_PTR")
## print("...found")
## except:
## print(" ...not found")
2番目のstdafx.hはVisual Studioでビルドプロセスをスピードアップするためのprecompiled headerというファイルとのこと。Visual Studioを使わないので不要と思われる。includeを削除しようと思ったがかなりのファイル数になるので、代わりに展開先のC++フォルダにstdafx.hという名前のからファイルを追加した
今度は展開先のファイルを使ってpip
(qfix) C:\Users\user\git\qfix>pip install .\quickfix-1.15.1
大量のtype cast警告の後で以下のfatal errorがでて失敗
HttpConnection.obj : error LNK2001: unresolved external symbol __imp_WSAGetLastError
HttpConnection.obj : error LNK2001: unresolved external symbol __imp_select
Utility.obj : error LNK2001: unresolved external symbol __imp_setsockopt
Utility.obj : error LNK2001: unresolved external symbol __imp_ioctlsocket
Utility.obj : error LNK2001: unresolved external symbol __imp_htons
Utility.obj : error LNK2001: unresolved external symbol __imp_getsockopt
Utility.obj : error LNK2001: unresolved external symbol __imp_recv
Utility.obj : error LNK2001: unresolved external symbol __imp_inet_ntoa
Utility.obj : error LNK2001: unresolved external symbol __imp_connect
Utility.obj : error LNK2001: unresolved external symbol __imp_ntohs
Utility.obj : error LNK2001: unresolved external symbol __imp_socket
Utility.obj : error LNK2001: unresolved external symbol __imp_send
Utility.obj : error LNK2001: unresolved external symbol __imp_getsockname
Utility.obj : error LNK2001: unresolved external symbol __imp_inet_addr
Utility.obj : error LNK2001: unresolved external symbol __imp_getpeername
Utility.obj : error LNK2001: unresolved external symbol __imp_WSAStartup
Utility.obj : error LNK2001: unresolved external symbol __imp_listen
Utility.obj : error LNK2001: unresolved external symbol __imp_shutdown
Utility.obj : error LNK2001: unresolved external symbol __imp_gethostbyname
Utility.obj : error LNK2001: unresolved external symbol __imp_closesocket
Utility.obj : error LNK2001: unresolved external symbol __imp_bind
Utility.obj : error LNK2001: unresolved external symbol __imp_accept
Utility.obj : error LNK2001: unresolved external symbol __imp_WSACleanup
build\lib.win-amd64-cpython-312\_quickfix.cp312-win_amd64.pyd : fatal error LNK1120: 23 unresolved externals
調べたところws2_32.libにうまくリンクできていないのが原因とのこと。展開先フォルダのUtility.hに以下を追加
#pragma comment (lib, "ws2_32.lib")
再度pipしたところ警告文も消え、無事インストールできた。