-
-
Save wenchy/64db1636845a3da0c4c7 to your computer and use it in GitHub Desktop.
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 |
Thanks! Very useful.
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)
$(patsubst %.cpp,%.o,$ (SRCS)): substitute all ".cpp" file name strings to ".o" file name strings
OBJS :=
all: $(TARGET)
#gcc -o ProC_Utility.o -c ProC_Utility.c
%.o: %.cpp
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'
Thanks for this!
Helped me out as a novice with
make