我的Windows 8.1機器上安裝了MinGW,我正在使用它來開發可移植到Unix/Linux系統的C++代碼,以代替能夠雙啓動Ubuntu或類似系統。MinGW在Windows上製作
我有一個通用的生成文件,應該用於構建項目,但由於某種原因,Windows上的find
命令無法找到該項目的源文件。我得到這個錯誤:
File not found - *.cpp
Makefile:32: *** mixed implicit and normal rules. Stop.
下面是我用(我將它改編自this博客,從博客的基本工程結構一起生成文件:
CC := g++ # This is the main compiler
# CC := clang --analyze # and comment out the linker last line for sanity
SRCDIR := src # Directory for source code
BUILDDIR := build # Directory containing all object files, which are removed on "make clean"
TARGET := bin/runner # bin/runner contains the main executable for project
# bin/ contains all other executables in the project (such as tests)
SRCEXT := cpp # File extension of source code
# Look for all the source files in SRCDIR with the file extension specified above
SOURCES := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
# Name all object files the same root name as the source files from which they came, but add a .o extension to the end
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
# The -g flag specifies that debugging information should be produced in the native format of the OS
CFLAGS := -g # -Wall
# Various flags for libraries that might need to be linked
LIB := -pthread -lmongoclient -L lib -lboost_thread-mt -lboost_filesystem-mt -lboost_system-mt
# Ensures that all header files (in the include/ folder) are accessible for build
INC := -I include
# Show the components that are currently being compiled/linked
# Also, this is the main procedure for make: The TARGET is built from the objects, and
# object files are built from source
$(TARGET): $(OBJECTS)
@echo " Linking..."
@echo " $(CC) $^ -o $(TARGET) $(LIB)"; $(CC) $^ -o $(TARGET) $(LIB)
$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
@mkdir -p $(BUILDDIR)
@echo " $(CC) $(CFLAGS) $(INC) -c -o [email protected] $<"; $(CC) $(CFLAGS) $(INC) -c -o [email protected] $<
# Directives for "make clean" which cleans all object files out of the build/ folder
clean:
@echo " Cleaning...";
@echo " $(RM) -r $(BUILDDIR) $(TARGET)"; $(RM) -r $(BUILDDIR) $(TARGET)
# Tests
# tester:
# $(CC) $(CFLAGS) test/tester.cpp $(INC) $(LIB) -o bin/tester
# Spikes
# ticket:
# $(CC) $(CFLAGS) spikes/ticket.cpp $(INC) $(LIB) -o bin/ticket
# Destroys everything in the build/ and bin/runner/ folders. Does not clean test executables.
.PHONY: clean
如果我打開一個增強的控制檯我的項目的根目錄,並運行find src/ -name '*.cpp'
,我得到同樣的錯誤,如上所示。從根目錄運行dir
Windows命令也找不到cpp文件。但是,從src
目錄運行時,dir
可以找到我的所有源文件,而find
cann OT。是否有一個原因?