Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not build on Windows #45

Open
mattn opened this issue Feb 28, 2018 · 0 comments
Open

Can not build on Windows #45

mattn opened this issue Feb 28, 2018 · 0 comments

Comments

@mattn
Copy link

mattn commented Feb 28, 2018

-- Found PythonInterp: C:/msys64/mingw64/bin/python2.7.exe (found version "2.7.14") 
CMake Error at C:/msys64/mingw64/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find PythonConfig (missing: PYTHON_COMPILE_FLAGS
  PYTHON_LINK_FLAGS)
Call Stack (most recent call first):
  C:/msys64/mingw64/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
  cmake/FindPythonConfig.cmake:27 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:31 (find_package)

python3-config is not executable file on Windows. Just shell-script for msys2/mingw64. So I created batch file like below.

python3.6-config.cmd

@echo off
c:\msys64\usr\bin\bash.exe c:\msys64\mingw64\bin\python3.6m-config %*

And modified some files.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index f19c831..bc02187 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -46,7 +46,7 @@ set_target_properties(cpsm_core PROPERTIES COMPILE_FLAGS "-fPIC")
 add_library(cpsm_py SHARED src/ctrlp_util.cc src/python_extension.cc)
 target_link_libraries(cpsm_py cpsm_core)
 set_target_properties(cpsm_py PROPERTIES COMPILE_FLAGS ${PYTHON_COMPILE_FLAGS})
-set_target_properties(cpsm_py PROPERTIES LINK_FLAGS ${PYTHON_LINK_FLAGS})
+set_target_properties(cpsm_py PROPERTIES LINK_FLAGS "-Wl,--whole-archive ${PYTHON_LINK_FLAGS} -Wl,--no-whole-archive -Wl,-Bstatic -lstdc++ -Wl,-Bdynamic")
 set_target_properties(cpsm_py PROPERTIES PREFIX "")
 if(APPLE)
   set_target_properties(cpsm_py PROPERTIES SUFFIX ".so")
@@ -55,7 +55,7 @@ install(TARGETS cpsm_py DESTINATION ${PROJECT_SOURCE_DIR}/autoload)
 install(TARGETS cpsm_py DESTINATION ${PROJECT_SOURCE_DIR}/bin)
 
 add_executable(cpsm_cli src/cpsm_cli_main.cc)
-target_link_libraries(cpsm_cli cpsm_core ${Boost_PROGRAM_OPTIONS_LIBRARIES})
+target_link_libraries(cpsm_cli ${Boost_PROGRAM_OPTIONS_LIBRARIES} cpsm_core)
 install(TARGETS cpsm_cli DESTINATION ${PROJECT_SOURCE_DIR}/bin)
 
 enable_testing()
diff --git a/cmake/FindPythonConfig.cmake b/cmake/FindPythonConfig.cmake
index 6a69b75..176b9b8 100644
--- a/cmake/FindPythonConfig.cmake
+++ b/cmake/FindPythonConfig.cmake
@@ -16,7 +16,11 @@ include(FindPackageHandleStandardArgs)
 
 find_package(PythonInterp)
 if(PYTHONINTERP_FOUND)
-  set(_Python_config "${PYTHON_EXECUTABLE}-config")
+  if(WIN32)
+    set(_Python_config "${PYTHON_EXECUTABLE}-config.cmd")
+  else(WIN32)
+    set(_Python_config "${PYTHON_EXECUTABLE}-config")
+  endif(WIN32)
   execute_process(COMMAND ${_Python_config} "--includes" OUTPUT_VARIABLE PYTHON_COMPILE_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
   execute_process(COMMAND ${_Python_config} "--ldflags" OUTPUT_VARIABLE PYTHON_LINK_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
   string(CONCAT _Python_config_message ${PYTHON_COMPILE_FLAGS} "; " ${PYTHON_LINK_FLAGS})

-Wl,--whole-archive ${PYTHON_LINK_FLAGS} is required to avoid to fix order of -l specified. This is ugly workaround. Please help me to fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant