问题
My problem: in a Makefile which I use in both the MSYS and the MSYS2 environment I know a path, PYTHON_ROOT_DIR, which shall be used at compilation time in a C++ program. Problem is PYTHON_ROOT_DIR is in the Makefile known as posix style path such as /mingw64/bin
, where in the C++ program it shall have a form like "C:\\prog64\\msys64\\mingw64\\bin"
. Additional challenge is that depending on a configuration variable PYTHONMAJOR the path shall be wide characters or normal characters.
My question: how do I solve this in the Makefile without a need to install additional programs/scripts in the msys or msys2 environments?
回答1:
Part of the question is addressed in msys path conversion (or cygpath for msys?), namely how to convert a msys style path to a windows style path. My full solution in the Makefile is:
ifeq ($(PYTHONMAJOR),3)
L=L
endif
DEFINES += -DPYTHON_ROOT_DIR=$(L)'"'$(shell (cmd //c echo $(PYTHON_ROOT_DIR)) | sed 's|/|\\\\\\\\|g')'"'
which defines the preprocessor symbol PYTHON_ROOT_DIR with the proper path.
来源:https://stackoverflow.com/questions/40257679/how-do-i-define-a-path-from-an-msys-makefile-for-a-c-program