From 984432026855497931020621d2cc82113211fa1c Mon Sep 17 00:00:00 2001 From: msincenselee Date: Mon, 26 Feb 2018 09:34:31 +0800 Subject: [PATCH] =>Py3.5 in linux compile --- vnpy/api/ctp/CMakeLists.txt | 21 +++++++++++++-------- vnpy/api/ctp/build.sh | 2 +- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/vnpy/api/ctp/CMakeLists.txt b/vnpy/api/ctp/CMakeLists.txt index 0893838a..eb8d98db 100644 --- a/vnpy/api/ctp/CMakeLists.txt +++ b/vnpy/api/ctp/CMakeLists.txt @@ -46,7 +46,7 @@ option(BUILD_CTP_MD "build ctp md" ON) if (BUILD_CTP_MD) add_definitions(-DBUILD_CTP_MD) set(CTP_MD_PATH vnctpmd/vnctpmd) - include_directories(CTP_MD_PATH) + include_directories(${CTP_MD_PATH}) set(VN_CTP_MD_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/vnctpmd/vnctpmd/vnctpmd.cpp) add_library(vnctpmd SHARED ${VN_CTP_MD_SOURCE}) endif() @@ -54,11 +54,12 @@ option(BUILD_CTP_TD "build ctp td" ON) if (BUILD_CTP_TD) add_definitions(-DBUILD_CTP_TD) set(CTP_TD_PATH vnctptd/vnctptd) - include_directories(CTP_TD_PATH) + include_directories(${CTP_TD_PATH}) set(VN_CTP_TD_SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/vnctptd/vnctptd/vnctptd.cpp) add_library(vnctptd SHARED ${VN_CTP_TD_SOURCE}) endif() + # 设置Python所在的目录 set(PYTHON_LIBRARY ) if (WIN32) @@ -68,19 +69,22 @@ find_library(PYTHON_LIBRARY PATHS C:/Python27/libs) include_directories(${PYTHON_INCLUDE_PATH}) else() -set(PYTHON_INCLUDE_PATH /home/tensorflow/anaconda3/envs/py35/include) +set(PYTHON_INCLUDE_PATH /home/tensorflow/anaconda3/envs/py35/include/python3.5m) find_library(PYTHON_LIBRARY - NAMES python35 - PATHS /home/tensorflow/anaconda3/envs/py35/lib) + NAMES python3.5 + PATHS /home/tensorflow/anaconda3/envs/py35/lib/) include_directories(${PYTHON_INCLUDE_PATH}) endif() +# hard code virtual environment +set (PYTHON_LIBRARY /home/tensorflow/anaconda3/envs/py35/lib/libpython3.so) + # 链接boost库,anaconda if (WIN32) set(Boost_USE_STATIC_LIBS ON) #链接boost静态库 endif() set(Boost_USE_MULTITHREADED ON) -find_package(Boost 1.55.0 COMPONENTS python thread date_time system chrono REQUIRED) # 如果boost库没有完全编译,需要将编译的库明确地指出,否者message(${Boost_LIBRARIES})会出错 +find_package(Boost 1.66.0 COMPONENTS locale thread date_time system chrono python3 REQUIRED) # 如果boost库没有完全编译,需要将编译的库明确地指出,否者message(${Boost_LIBRARIES})会出错 if(Boost_FOUND) include_directories(${Boost_INCLUDE_DIRS}) endif() @@ -88,8 +92,9 @@ endif() # 去掉生成的so文件名中前缀的lib set_target_properties(vnctpmd PROPERTIES PREFIX "") +set(MY_BOOST /usr/local/lib) # 链接生成.so文件 -target_link_libraries(vnctpmd ${Boost_LIBRARIES} ${PYTHON_LIBRARY} ${CTPAPI_MD_LIBRARY}) +target_link_libraries(vnctpmd ${MY_BOOST} ${Boost_LIBRARIES} ${PYTHON_LIBRARY} ${CTPAPI_MD_LIBRARY}) # 将生成的dll文件后缀名修改为pyd(仅在windows下) set(MD_DLL "${LIBRARY_OUTPUT_PATH}/Release/vnctpmd.dll") @@ -99,7 +104,7 @@ endif() # 和上面的MD相同 set_target_properties(vnctptd PROPERTIES PREFIX "") -target_link_libraries(vnctptd ${Boost_LIBRARIES} ${PYTHON_LIBRARY} ${CTPAPI_TD_LIBRARY}) +target_link_libraries(vnctptd ${MY_BOOST} ${Boost_LIBRARIES} ${PYTHON_LIBRARY} ${CTPAPI_TD_LIBRARY}) set(TD_DLL ${LIBRARY_OUTPUT_PATH}/Release/vnctptd.dll) if (EXISTS ${TD_DLL}) file(RENAME ${TD_DLL} ${LIBRARY_OUTPUT_PATH}/Release/vnctptd.pyd) diff --git a/vnpy/api/ctp/build.sh b/vnpy/api/ctp/build.sh index c6ff3173..80873326 100644 --- a/vnpy/api/ctp/build.sh +++ b/vnpy/api/ctp/build.sh @@ -1,6 +1,6 @@ #!/bin/bash # Written by Suzhengchun on 20160213 - +# updated by Incenselee on 20180226, support PY3 in Linux set -e BUILDDIR=build rm -rf $BUILDDIR