jor*_*gen 1 windows makefile path relative-path msys2
I have a set of programs that compile fine on Ubuntu and I'm working on a setup to compile on Windows as well. I'm using MSYS2.
There is a main Makefile which looks like this:
#### Project main directory
DIR_MAIN=$(shell pwd)
#### Compile all
all:
@$(MAKE) -C src/Misc DIR_MAIN=$(DIR_MAIN)
@$(MAKE) -C src/CF_states DIR_MAIN=$(DIR_MAIN)
Run Code Online (Sandbox Code Playgroud)
etcetera. In src/
there are folders each who contain a specific Makefile for that project. They have the following structure:
#### Directories and flags
ifndef $(DIR_MAIN)
DIR_MAIN=../..
endif
DIR_EXE=$(DIR_MAIN)/Programs
DIR_SRC=$(DIR_MAIN)/src/Misc
DIR_SFMT_SRC=$(DIR_MAIN)/src/sfmt
DIR_BLD=$(DIR_MAIN)/build/Misc
COMP=g++
COMPILE_FLAGS= -std=c++11 -O3 -lstdc++ -msse2
LINK_FLAGS= -O3 -fopenmp -lgsl -lgslcblas -lm -lhdf5_cpp -lhdf5
#### Compile all
all: setup $(DIR_BLD)/input.o $(DIR_BLD)/misc_sphere.o $(DIR_BLD)/misc.o
setup:
@mkdir -p $(DIR_BLD)
@mkdir -p $(DIR_EXE)
#### Misc source
$(DIR_BLD)/input.o: $(DIR_SRC)/input.cpp $(DIR_SRC)/input.h $(DIR_SRC)/misc_sphere.h
${COMP} -c input.cpp ${COMPILE_FLAGS} -o $@
$(DIR_BLD)/misc_sphere.o: $(DIR_SRC)/misc_sphere.cpp $(DIR_SRC)/misc_sphere.h $(DIR_SRC)/misc.h
${COMP} -c misc_sphere.cpp ${COMPILE_FLAGS} -o $@
$(DIR_BLD)/misc.o: $(DIR_SRC)/misc.cpp $(DIR_SRC)/misc.h
${COMP} -c misc.cpp ${COMPILE_FLAGS} -o $@
Run Code Online (Sandbox Code Playgroud)
In this way the specific Makefiles can be run from their folder in src/
, using relative paths, or from the main Makefile, using absolute paths.
这在Ubuntu上有效,但在MSYS2上只有相对路径有效,即从其文件夹中运行每个特定的Makefile。当我使用运行主Makefile时
mingw32-make.exe
Run Code Online (Sandbox Code Playgroud)
我得到错误
$ mingw32-make.exe
mingw32-make[1]: Entering directory 'C:/msys64/home/Jorgen/fqhe_mc_sphere/src/Misc'
mingw32-make[1]: *** No rule to make target '/home/Jorgen/fqhe_mc_sphere/src/Misc/input.cpp', needed by '/home/Jorgen/fqhe_mc_sphere/build/Misc/input.o'. Stop.
mingw32-make[1]: Leaving directory 'C:/msys64/home/Jorgen/fqhe_mc_sphere/src/Misc'
Makefile:8: recipe for target 'all' failed
mingw32-make: *** [all] Error 2
Run Code Online (Sandbox Code Playgroud)
即使文件/home/Jorgen/fqhe_mc_sphere/src/Misc/input.cpp
存在,也可以使用检查ls
。知道为什么吗?
编辑:
将第一个目标更改为相对路径(结果除外),即
$(DIR_BLD)/input.o: input.cpp input.h misc_sphere.h
${COMP} -c input.cpp ${COMPILE_FLAGS} -o $@
Run Code Online (Sandbox Code Playgroud)
输出对象文件出现类似错误:
Fatal error: can't create /home/Jorgen/fqhe_mc_sphere/build/Misc/input.o: No such file or directory
Run Code Online (Sandbox Code Playgroud)
虽然该文件夹/home/Jorgen/fqhe_mc_sphere/build/Misc/
确实存在。
我尝试以管理员身份运行MSYS2,但没有帮助。
您正在将POSIX路径与Windows路径混合并运行不了解POSIX路径的mingw32-make。
如user657267所建议,请使用make代替。否则,您可以使用mklink / D来制作技巧,以在Windows上创建与POSIX等效的路径。在这里,您应该最有可能将C:\ home链接到C:\ msys64 \ home。
归档时间: |
|
查看次数: |
417 次 |
最近记录: |