简体   繁体   中英

“Can not find file” makefile error

I am trying to compile a C++ program using make. I want it to read the source files from the src folder. Place the object files in the build folder, and put the exe in the bin folder.

I get the following error

/bin/wavfiletool.exe -g -O2 process_begin: CreateProcess(NULL, /bin/wavfiletool.exe -g -O2, ...) failed. make (e=2): The system cannot find the file specified.

UPDATE: The problem was I put g++ in for my compiler var instead of &(CC)...woops.

But now it says g++: fatal error: no input files I am running make using a batch file that sets the environment variables.

SET PATH=C:\Make\GnuWin32\bin;C:\MinGW\bin
make %1

My makefile is as follows.

CC := g++
CFLAGS := -g -O2
BIN_DIR := /bin
BUILD_DIR := /build
SRC_DIR := /src
TARGET := wavfiletool.exe
SOURCES  := $(wildcard $(SRC_DIR)/*.c)
OBJECTS  := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)

$(BIN_DIR)/$(TARGET): $(OBJECTS)
    $(G++) $@ $(CFLAGS) $(OBJECTS)

$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
    @$(CC) $(CFLAGS) -c $< -o $@

You haven't set the $(G++) variable anywhere so the recipe line for the $(BIN_DIR)/$(TARGET) target is trying to run $@ instead of the compiler.

Also you are missing -o on that compilation line so were $(G++) set to g++ correctly you would end up running:

g++ /bin/wavfiletool.exe -g -O2 $(OBJECTS)

which likely isn't what you want.

That being said you probably don't want to be writing directly into /bin either. Did you mean ./bin for a bin directory in the local directory?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM