0
我是makefile的新手用戶,我創建了規則(run1,run2等)分別執行c和C++對象(單獨編譯成功c/C++,也需要單獨執行它們),但它似乎並不如預期的工作,任何人都可以告訴被它出了問題以及如何糾正它使用Makefile執行多個程序(c/C++)
TARGET_EXEC ?=
BUILD_DIR ?= .
SRC_DIRS ?= .
SRCS := $(shell find $(SRC_DIRS) -name *.cpp -or -name *.c)
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
CC = gcc
CXX = g++
CFLAGS = -g -Wall
CPPFLAGS = -g -lws2_32 -Wno-write-strings
.PHONY: all run1 run2 run3 clean
all: $(BUILD_DIR)/$(TARGET_EXEC)
$(BUILD_DIR)/$(TARGET_EXEC): $(OBJS)
@echo "Build completed"
# c source
$(BUILD_DIR)/%.c.o: %.c
@echo "Compiling C sources"
@$(CC) $(CFLAGS) $< -o $(basename $(<F))
@echo "Compiled successfully"
# c++ source
$(BUILD_DIR)/%.cpp.o: %.cpp
@echo "Compiling C++ sources"
@$(CXX) -o $(basename $(<F)) $(CXXFLAGS) $< $(CPPFLAGS)
@echo "Compiled successfully"
clean:
@echo "Cleaning"
@$(RM) -r *.exe
@echo "Cleaned up"
run1: $(OBJS)
$(OBJS)=$(SRCS)
$(SRC_DIRS)/%.c.o: %.c
@echo "from run1"
./$(basename $(<F)) ${ARGS}
run2: $(OBJS)
$(OBJS)=$(SRCS)
$(SRC_DIRS)/%.cpp.o: %.cpp
@echo "from run2"
./$(basename $(<F)) ${ARGS}
命令:make run1
輸出:
from run1
-> execution
from run2
-> execution
預期輸出
from run1
--> execution of exe created
而且我想通過我從link簡稱傳遞,使運行參數。例如:
make ARG="-p TCP -n 127.0.0.1 -e 10006 -l 1" run2
也讓我知道如果這可以做到沒有任何問題。
可能的重複[如何構建多個具有相似名稱的目標?](http://stackoverflow.com/questions/42662359/how-to-build-multiple-targets-with-similar-name) – jjb
我是沒有看到這是如何重複。它沒有解決OP的問題。 – blackghost