How do I define a path from an MSYS Makefile for a C++ program?

回眸只為那壹抹淺笑 提交于 2019-12-12 05:06:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!