Last active
January 16, 2024 15:36
-
-
Save wenchy/64db1636845a3da0c4c7 to your computer and use it in GitHub Desktop.
Compile all .cpp files into one target under the current directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CC := g++ | |
CFLAGS := -Wall -g | |
TARGET := test | |
# $(wildcard *.cpp /xxx/xxx/*.cpp): get all .cpp files from the current directory and dir "/xxx/xxx/" | |
SRCS := $(wildcard *.cpp) | |
# $(patsubst %.cpp,%.o,$(SRCS)): substitute all ".cpp" file name strings to ".o" file name strings | |
OBJS := $(patsubst %.cpp,%.o,$(SRCS)) | |
all: $(TARGET) | |
$(TARGET): $(OBJS) | |
$(CC) -o $@ $^ | |
%.o: %.cpp | |
$(CC) $(CFLAGS) -c $< | |
clean: | |
rm -rf $(TARGET) *.o | |
.PHONY: all clean |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After compiling , when all .o are ready from all cpp. It throws error undefined reference for all files when creating final binary.
my modified script is
CC := g++
CFLAGS := -Wall -g
TARGET := proton
export REL_PATH := $(shell pwd)
INC :=-I$(REL_PATH)/include
LIBS += -lz -lrt -lpthread -lbluetooth -lssl -lcrypt -lcrypto
$(wildcard .cpp /xxx/xxx/.cpp): get all .cpp files from the current directory and dir "/xxx/xxx/"
SRCS := $(wildcard *.cpp)
OBJS :=$(patsubst %.cpp,%.o,$ (SRCS))
all: $(TARGET)$(INC) -L$ (LIBS)
$(TARGET): $ (OBJS)
$(CC) -o $ @ $^ $ (INC) -L$(LIBS)
#gcc -o ProC_Utility.o -c ProC_Utility.c
%.o: %.cpp
$(CC) $ (CFLAGS) -c $< $ (INC) -L$(LIBS)
clean:
rm -rf $(TARGET) *.o
.PHONY: all clean
------------------------------------------------------------------------------------------------------------------------------------ ERROR shown below -----------
CMDFTPUp.o: In function
CMDFTPUp::RunBlocking(char*, char*)': /home/workstation21/LDF_Integration_03/proton17dec/test/proton/CMDFTPUp.cpp:111: undefined reference to
mkdir_r'