PyCTP icon indicating copy to clipboard operation
PyCTP copied to clipboard

linux版编译问题

Open bixiang opened this issue 6 years ago • 9 comments

用linux版本时,编译后不能自动生成pyctp文件,该如何解决

bixiang avatar Mar 26 '18 08:03 bixiang

不应出现此现象,检查是否忘记安装 python-devel 库.

shizhuolin avatar Mar 26 '18 08:03 shizhuolin

已经装了,我用的是ubuntu 16.04,已经装了python-dev。

bixiang avatar Mar 26 '18 08:03 bixiang

执行python3 setup.py build后 pyctp.......so 文件应在build目录中自动生成, 如失败,把错误信息贴上来,

shizhuolin avatar Mar 26 '18 08:03 shizhuolin

bixiang@bixiang-ThinkCentre-M8600t-N085:~/PyCTP$ python3 setup.py build
running build
running build_ext
building 'PyCTP' extension
creating build
creating build/temp.linux-x86_64-3.5
creating build/temp.linux-x86_64-3.5/src
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-6tVwKN/python3.5-3.5.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I./v6.3.6_20160606_api_tradeapi_linux64 -I/usr/include/python3.5m -c ./src/stdafx.cpp -o build/temp.linux-x86_64-3.5/./src/stdafx.o -std=c++11
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-6tVwKN/python3.5-3.5.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I./v6.3.6_20160606_api_tradeapi_linux64 -I/usr/include/python3.5m -c ./src/PyCTP.cpp -o build/temp.linux-x86_64-3.5/./src/PyCTP.o -std=c++11
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-6tVwKN/python3.5-3.5.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I./v6.3.6_20160606_api_tradeapi_linux64 -I/usr/include/python3.5m -c ./src/UserApiDataType.cpp -o build/temp.linux-x86_64-3.5/./src/UserApiDataType.o -std=c++11
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-6tVwKN/python3.5-3.5.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I./v6.3.6_20160606_api_tradeapi_linux64 -I/usr/include/python3.5m -c ./src/UserApiStruct.cpp -o build/temp.linux-x86_64-3.5/./src/UserApiStruct.o -std=c++11
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-6tVwKN/python3.5-3.5.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I./v6.3.6_20160606_api_tradeapi_linux64 -I/usr/include/python3.5m -c ./src/MdApi.cpp -o build/temp.linux-x86_64-3.5/./src/MdApi.o -std=c++11
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.5-6tVwKN/python3.5-3.5.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I./v6.3.6_20160606_api_tradeapi_linux64 -I/usr/include/python3.5m -c ./src/TraderApi.cpp -o build/temp.linux-x86_64-3.5/./src/TraderApi.o -std=c++11
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
creating build/lib.linux-x86_64-3.5
x86_64-linux-gnu-g++ -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fdebug-prefix-map=/build/python3.5-6tVwKN/python3.5-3.5.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.5/./src/stdafx.o build/temp.linux-x86_64-3.5/./src/PyCTP.o build/temp.linux-x86_64-3.5/./src/UserApiDataType.o build/temp.linux-x86_64-3.5/./src/UserApiStruct.o build/temp.linux-x86_64-3.5/./src/MdApi.o build/temp.linux-x86_64-3.5/./src/TraderApi.o -L./v6.3.6_20160606_api_tradeapi_linux64 -Wl,--enable-new-dtags,-R./ -lthostmduserapi -lthosttraderapi -o build/lib.linux-x86_64-3.5/PyCTP.cpython-35m-x86_64-linux-gnu.so
running build_scripts
creating build/scripts-3.5
copying ./src/test_PyCTP.py -> build/scripts-3.5
changing mode of build/scripts-3.5/test_PyCTP.py from 644 to 755
bixiang@bixiang-ThinkCentre-M8600t-N085:~/PyCTP$ cd build/
bixiang@bixiang-ThinkCentre-M8600t-N085:~/PyCTP/build$ ls
lib.linux-x86_64-3.5  scripts-3.5  temp.linux-x86_64-3.5
bixiang@bixiang-ThinkCentre-M8600t-N085:~/PyCTP/build$ cd scripts-3.5/
bixiang@bixiang-ThinkCentre-M8600t-N085:~/PyCTP/build/scripts-3.5$ ls
test_PyCTP.py
bixiang@bixiang-ThinkCentre-M8600t-N085:~/PyCTP/build/scripts-3.5$ 

bixiang avatar Mar 26 '18 09:03 bixiang

build/lib.linux-x86_64-3.5/PyCTP.cpython-35m-x86_64-linux-gnu.so 这是编译后的文件,直接放到项目根目录

shizhuolin avatar Mar 26 '18 09:03 shizhuolin

我已经照做了,可是如何让其自动生成pyd文件呢?

Traceback (most recent call last):
  File "test_PyCTP.py", line 10, in <module>
    import PyCTP
ImportError: No module named 'PyCTP'

bixiang avatar Mar 26 '18 09:03 bixiang

在linux平台使用类似 PyCTP.cpython-35m-x86_64-linux-gnu.so 这样的文件(不可改文件名),把这个文件放到 test_PyCTP.py所在目录即可. 只有在windows平台才会生成并且使用PyCTP.pyd文件, 这是python在不同的平台差异.

shizhuolin avatar Mar 26 '18 09:03 shizhuolin

移过去后要如何使用呢?因为仅仅就移过去,import PyCTP依然会报这个错呀

bixiang avatar Mar 26 '18 09:03 bixiang

需要将 v6.3.6_20160606_api_tradeapi_linux64 目录中的 libthosttraderapi.so, libthostmduserapi.so 文件也复制到 PyCTP.cpython-35m-x86_64-linux-gnu.so 和 *.py 同一个目录中. 原因是 PyCTP.cpython-35m-x86_64-linux-gnu.so 只是包装了功能,真正的执行其实还是由 api_tradeapi_linux64 完成.

shizhuolin avatar Mar 26 '18 09:03 shizhuolin